/**
* sftp下载文件
*/
public static String downLoadFileSftp(String fileUrl, String accessName, String accessPassWord, String contentId)
throws CmsBasicException
{
JSch jsch = new JSch();
Session session = null;
UrlDecoder urlDecoder = new UrlDecoder();
urlDecoder.decodeUrl(fileUrl);
String localFileName = null;
try
{
session = jsch.getSession(accessName, urlDecoder.getIp(), urlDecoder.getPort());
session.setConfig("StrictHostKeyChecking", "no");
session.setPassword(accessPassWord);
session.connect();
Channel channel = session.openChannel("sftp");
channel.connect();
ChannelSftp sftpChannel = (ChannelSftp) channel;
// 1.根据url解析参数
sftpChannel.cd(urlDecoder.getPath());
localFileName = getLocalFile(urlDecoder, contentId);
sftpChannel.get(urlDecoder.getFileName(), localFileName);
sftpChannel.exit();
session.disconnect();
}
catch (JSchException e)
{
throw new CmsBasicException("sftp connect faild");
}
catch (SftpException e)
{
throw new CmsBasicException("sftp connect faild");
}
return localFileName;
}
java sftp下载文件
最新推荐文章于 2023-03-13 15:27:57 发布