Looly 6 years ago
parent
commit
870e22de00
2 changed files with 17 additions and 1 deletions
  1. 1 0
      CHANGELOG.md
  2. 16 1
      hutool-extra/src/main/java/cn/hutool/extra/ssh/Sftp.java

+ 1 - 0
CHANGELOG.md

@@ -8,6 +8,7 @@
 ### 新特性
 ### 新特性
 * 【core】        CollUtil增加filterNew等方法(原filter变更为filterNew,新增filter)
 * 【core】        CollUtil增加filterNew等方法(原filter变更为filterNew,新增filter)
 * 【crypto】      Sign增加setParameter方法
 * 【crypto】      Sign增加setParameter方法
+* 【extra】        Sftp得put方法增加进度支持(issue#518@Github)
 
 
 ### Bug修复
 ### Bug修复
 
 

+ 16 - 1
hutool-extra/src/main/java/cn/hutool/extra/ssh/Sftp.java

@@ -12,6 +12,7 @@ import com.jcraft.jsch.ChannelSftp.LsEntry;
 import com.jcraft.jsch.ChannelSftp.LsEntrySelector;
 import com.jcraft.jsch.ChannelSftp.LsEntrySelector;
 import com.jcraft.jsch.Session;
 import com.jcraft.jsch.Session;
 import com.jcraft.jsch.SftpException;
 import com.jcraft.jsch.SftpException;
+import com.jcraft.jsch.SftpProgressMonitor;
 
 
 import cn.hutool.core.io.FileUtil;
 import cn.hutool.core.io.FileUtil;
 import cn.hutool.core.lang.Filter;
 import cn.hutool.core.lang.Filter;
@@ -373,8 +374,22 @@ public class Sftp extends AbstractFtp {
 	 * @return this
 	 * @return this
 	 */
 	 */
 	public Sftp put(String srcFilePath, String destPath, Mode mode) {
 	public Sftp put(String srcFilePath, String destPath, Mode mode) {
+		return put(srcFilePath, destPath, null, mode);
+	}
+	
+	/**
+	 * 将本地文件上传到目标服务器,目标文件名为destPath,若destPath为目录,则目标文件名将与srcFilePath文件名相同。
+	 * 
+	 * @param srcFilePath 本地文件路径
+	 * @param destPath 目标路径,
+	 * @param monitor 上传进度监控,通过实现此接口完成进度显示
+	 * @param mode {@link Mode} 模式
+	 * @return this
+	 * @since 4.6.5
+	 */
+	public Sftp put(String srcFilePath, String destPath, SftpProgressMonitor monitor, Mode mode) {
 		try {
 		try {
-			channel.put(srcFilePath, destPath, mode.ordinal());
+			channel.put(srcFilePath, destPath, monitor, mode.ordinal());
 		} catch (SftpException e) {
 		} catch (SftpException e) {
 			throw new JschRuntimeException(e);
 			throw new JschRuntimeException(e);
 		}
 		}