From 870e22de004a988345101b310ff396eedc92bcf0 Mon Sep 17 00:00:00 2001 From: Looly Date: Mon, 2 Sep 2019 16:20:20 +0800 Subject: [PATCH] add put --- CHANGELOG.md | 1 + .../src/main/java/cn/hutool/extra/ssh/Sftp.java | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 20b958460..0c93caad4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ ### 新特性 * 【core】 CollUtil增加filterNew等方法(原filter变更为filterNew,新增filter) * 【crypto】 Sign增加setParameter方法 +* 【extra】 Sftp得put方法增加进度支持(issue#518@Github) ### Bug修复 diff --git a/hutool-extra/src/main/java/cn/hutool/extra/ssh/Sftp.java b/hutool-extra/src/main/java/cn/hutool/extra/ssh/Sftp.java index 459616fd8..4692fac7e 100644 --- a/hutool-extra/src/main/java/cn/hutool/extra/ssh/Sftp.java +++ b/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.Session; import com.jcraft.jsch.SftpException; +import com.jcraft.jsch.SftpProgressMonitor; import cn.hutool.core.io.FileUtil; import cn.hutool.core.lang.Filter; @@ -373,8 +374,22 @@ public class Sftp extends AbstractFtp { * @return this */ 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 { - channel.put(srcFilePath, destPath, mode.ordinal()); + channel.put(srcFilePath, destPath, monitor, mode.ordinal()); } catch (SftpException e) { throw new JschRuntimeException(e); }