SFTP Plug-in for Eclipse

SFTP插件为Eclipse提供了SFTP支持,具备文件与目录的导入、导出及同步等功能,支持多种认证方式及代理设置。该插件适用于Eclipse 3.3及以上版本。

SFTP Plug-in for Eclipse will add the SFTP support to Eclipse.
In the current implementation, SFTP client and SFTP Team provider has been provided.
SFTP Team provider allows you to synchronize files and directories between the workspace and a remote location as WebDAV and FTP support for Eclipse does, but by using ssh2 sftp protocol.

 

Features
The current version has the following features.

  • SFTP client (plug-in: com.jcraft.eclipse.sftp).
  • SFTP cliet is using Eclipse's internal SSH client,JSch.
  • SFTP Team provider (plug-in: com.jcraft.eclipse.team.sftp,com.jcraft.eclipse.target.sftp).
    • importing a remote directory into the workspace as a project by sftp.
    • exporting a folder to a remote directory by sftp.
    • synchronizing with the remote directory by sftp.
  • password, public-key and keyboard-interactive authentications.
  • HTTP and SOCKS5 proxies.
  • key pair generation.
  • host-key management.
  • The code is based on WebDAV and FTP support for Eclipse.
  • Plug-ins will work on Eclipse Platform 3.3 and later.
  • Plug-ins are licensed under the terms and conditions of EPL 1.0.

 

Installation
You need Eclipse SDK 3.3(or higher) to enjoy this software.

  1. Help > Software Updates > Find and Install...
  2. Choose Search for new features to install
  3. Click New Remote Site..., and then put http://eclipse.jcraft.com/ for the URL field.
  4. Choose SFTP Plug-in, and then click Select Required button.

For Eclipse SDK 3.2, try the Update Site http://eclipse.jcraft.com/3.2/

 

Tips

  • The location 'sftp://192.168.0.1/tmp' will allow you to get accesses to 'tmp' directory under user's home directory. On the other hand, 'sftp://192.168.0.1//tmp' will point to '/tmp' directory on the remote.

 

Download

  • eclipse-sftp_0.0.4.zip (124,091 bytes) md5sum:    cefc844a92a7d83c1fa4bfc6c0650862   eclipse-sftp_0.0.4.zip

 

Credits and Acknowledgments
This software has been developed by ymnk. The code has been based on "WebDAV and FTP support for Eclipse" initially written by IBM.

 

Comments/suggestions are accepted at eclipse-sftp@jcraft.com.

 

``SSH is a registered trademark and Secure Shell is a trademark of SSH Communications Security Corp (http://www.ssh.com)''

<think>我们正在讨论SFTP中的mput命令,但注意到SFTP的mput命令本身不支持正则表达式模式匹配。用户可能希望上传符合特定模式的文件,但需要找到替代方法。 根据之前的讨论,用户遇到了单引号导致模糊查询失败的问题,现在转向SFTP环境下的文件上传模式匹配。 关键点: 1. SFTP协议中的`mput`命令(在sftp交互模式下)通常只支持通配符(如*和?),但不支持完整的正则表达式。 2. 然而,在sftp命令行中,我们可以使用非交互模式并结合本地shell的通配符扩展来实现类似功能。 解决方案: 方案1:使用本地shell的通配符扩展(在sftp命令行中) 步骤: a. 在本地shell中,使用通配符模式匹配文件,然后通过sftp的命令行非交互模式上传。 b. 示例:假设要上传所有以“.txt”结尾的文件到远程服务器的`/upload`目录 ```bash sftp user@host << EOF cd /upload put *.txt bye EOF ``` 方案2:使用循环(当通配符模式较复杂时) ```bash for file in /path/to/local/*.pdf; do sftp user@host << EOF cd /remote/dir put "$file" bye EOF done ``` 方案3:使用lftp(如果可用)支持更丰富的模式匹配 lftp的`mput`命令支持`-f`选项指定文件列表,可以结合find命令使用正则表达式生成文件列表。 步骤: a. 使用find命令生成文件列表(支持正则表达式) b. 使用lftp的`mput`命令上传 示例: ```bash # 使用find生成文件列表(例如:匹配2023年1月1日至9日的日志文件) find . -regex '.*/log_2023010[1-9]\.txt' -print > filelist.txt # 使用lftp上传 lftp -u user,password sftp://host cd /remote/dir mput -f filelist.txt quit ``` 注意事项: 1. 在sftp的交互模式下,`mput`命令会提示确认每个文件,可以通过`-b`选项使用批处理模式避免交互(但sftp本身不支持在批处理中关闭提示,所以建议使用非交互脚本或lftp)。 2. 如果文件名包含空格,需要确保正确处理,通常在循环中使用双引号括起变量。 针对用户需求(正则表达式)的特别说明: sftp本身不支持正则表达式,所以我们需要借助本地shell工具(如find)来生成文件列表,然后通过循环或lftp上传。 示例:上传所有匹配`file_[0-9]{3}.txt`模式的文件(即file_后跟三位数字的txt文件) ```bash # 使用find和循环 find . -type f -regex '.*/file_[0-9]{3}\.txt' | while read file; do sftp user@host <<EOF cd /remote/dir put "$file" bye EOF done ``` 或者,如果文件数量大,使用lftp效率更高: ```bash find . -type f -regex '.*/file_[0-9]{3}\.txt' > filelist.txt lftp -u user,password sftp://host -e "cd /remote/dir; mput -f filelist.txt; quit" ``` 引用说明: 根据引用[1]中提到的`ncftp`,它可能是一个替代方案,但注意引用[1]描述的是`ncftp`是一个FTP浏览器程序,而引用[2]提到了`zip`等工具,但用户需求是SFTP。因此,我们主要考虑sftp和lftp。 总结: 由于sftp的mput命令不支持正则表达式,我们推荐使用本地shell工具(如find)生成文件列表,然后结合循环或lftp进行上传。 相关问题: 1. 如何在sftp中递归上传整个目录? 2. 如何避免sftp交互模式中的确认提示? 3. 除了lftp,还有哪些支持正则表达式上传的sftp客户端? 注意:在回答中,我们引用了用户提供的引用[1]和[2]中的部分工具(如ncftp),但指出它们可能不直接适用于SFTP正则表达式上传,因此主要解决方案围绕sftp和lftp展开。</think>### SFTP中使用正则表达式模式匹配的mput文件上传方案 SFTP协议本身不支持正则表达式模式匹配,但可通过以下方法实现类似功能: #### 一、核心问题分析 1. **SFTP限制**: - `mput`命令仅支持基础通配符(`*`和`?`),不支持完整正则表达式[^1] - 示例失败命令:`sftp> mput log_[0-9]{4}.txt` 会直接查找名为`log_[0-9]{4}.txt`的文件 2. **解决方案原理**: ```mermaid graph LR A[本地文件系统] --> B{Shell通配符扩展} B --> C[生成文件列表] C --> D[SFTP批量上传] ``` #### 二、具体实现方法 ##### 方法1:Shell通配符扩展(推荐) ```bash # 上传所有2023年的日志文件(log_2023*.txt) sftp user@host <<EOF cd /remote/path put log_2023*.txt exit EOF ``` - **支持模式**: - `log_2023??.txt`:匹配2023年后跟任意两字符的文件 - `report_Q[1-4].pdf`:匹配Q1到Q4的报告 ##### 方法2:结合find命令(复杂正则) ```bash # 查找并上传匹配 file_数字三位数.txt 的文件 find . -regex '.*/file_[0-9]{3}\.txt' -exec sftp user@host <<EOF cd /remote/dir put {} exit EOF \; ``` ##### 方法3:lftp工具(高级支持) ```bash # 安装lftp:sudo apt install lftp lftp sftp://user:password@host -e ' cd /remote/path; mput -E "invoice_202[0-9]{4}\.pdf"; # -E启用正则 quit ' ``` #### 三、关键注意事项 1. **特殊字符处理**: ```bash # 文件名含空格时使用双引号 put "Project *.docx" ``` 2. **批量操作优化**: ```bash # 生成文件列表再上传(适用于大量文件) find . -name "data_*.csv" > filelist.txt sftp user@host <<EOF cd /remote put -r $(cat filelist.txt | tr '\n' ' ') EOF ``` 3. **递归上传目录**: ```bash sftp> put -r Project_2023*/ # 上传所有Project_2023开头的目录 ``` #### 四、验证与调试技巧 1. 先本地测试模式匹配: ```bash ls -1 log_2023*.txt # 查看匹配结果 ``` 2. SFTP调试模式: ```bash sftp -v user@host # -v显示详细操作 ``` > ⚠️ **安全提示**:正则表达式中的特殊字符如`;`、`|`需过滤,防止命令注入: > ```bash > safe_pattern=$(echo "$user_input" | tr -d ';|&') # 使用$safe_pattern作为上传模式 > ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值