From 04c96a4c6b65eee1cf28a8c8784192094637ea55 Mon Sep 17 00:00:00 2001 From: xyli Date: Tue, 14 Feb 2023 15:23:26 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9SshService.java=E6=96=87?= =?UTF-8?q?=E4=BB=B6=EF=BC=8C=E6=B7=BB=E5=8A=A0download=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mpms/service/node/ssh/SshService.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/main/java/mpms/service/node/ssh/SshService.java b/src/main/java/mpms/service/node/ssh/SshService.java index d3b36a3..521322d 100644 --- a/src/main/java/mpms/service/node/ssh/SshService.java +++ b/src/main/java/mpms/service/node/ssh/SshService.java @@ -266,4 +266,28 @@ public class SshService extends BaseOperService implements BaseDynamic } } + /** + * 下载文件 + * + * @param sshModel 实体 + * @param remoteFile 远程文件 + * @param save 文件对象 + * @throws FileNotFoundException io + * @throws SftpException sftp + */ + public void download(SshModel sshModel, String remoteFile, File save) throws FileNotFoundException, SftpException { + Session session = null; + ChannelSftp channel = null; + OutputStream output = null; + try { + session = getSession(sshModel); + channel = (ChannelSftp) JschUtil.openChannel(session, ChannelType.SFTP); + output = new FileOutputStream(save); + channel.get(remoteFile, output); + } finally { + IoUtil.close(output); + JschUtil.close(channel); + JschUtil.close(session); + } + } } -- Gitee