sftp - 通过jsch将zip文件下载到sftp站点时,输入流随机关闭错误
问题描述
我试图从另一个国家的 sftp 服务器下载 zip 文件,但有时我无法获取带有以下错误代码的 zip 文件:
at com.jcraft.jsch.ChannelSftp._get(ChannelSftp.java:1160)
at com.jcraft.jsch.ChannelSftp.get(ChannelSftp.java:1006)
at com.jcraft.jsch.ChannelSftp.get(ChannelSftp.java:984)
at com.esb.eaml.util.SFTPUtil.get(Unknown Source)
at com.esb.eaml.job.JobKzDownloadProcessor.downloadKzFileFromLyods(Unknown Source)
at com.esb.eaml.job.JobKzDownloadProcessor.execute(Unknown Source)
at com.esb.eaml.job.JobKzDownloadProcessor.main(Unknown Source)
Caused by: java.io.IOException: inputstream is closed
at com.jcraft.jsch.ChannelSftp.fill(ChannelSftp.java:2884)
at com.jcraft.jsch.ChannelSftp.header(ChannelSftp.java:2908)
at com.jcraft.jsch.ChannelSftp._get(ChannelSftp.java:1062)
... 6 more
服务器所有者说他在服务器日志中没有发现任何错误。
我们使用 jsch-0.1.52.jar 进行 SFTP 连接。源代码如下所示:
boolean isOK = false;
FileOutputStream fos = null;
try {
if (initOK) {
logger.info("Downloading file from [" + srcPath + "] to [" + savePath + "]...");
fos = new FileOutputStream(savePath);
channelSftp.get(srcPath, fos);
isOK = true;
logger.info("Download file from [" + srcPath + "] to [" + savePath + "] successful.");
} else {
logger.error("Download file from [" + srcPath + "] to [" + savePath
+ "] failed, initial SFTP channel is not successful.");
}
} catch (FileNotFoundException e) {
logger.error("Download file from [" + srcPath + "] to [" + savePath
+ "] failed, savePath or savePath does not exist.", e);
} catch (SftpException e) {
logger.error("Download file from [" + srcPath + "] to [" + savePath + "] failed.", e);
}
return isOK;
解决方案
推荐阅读
- safari - iOS 15 上的 Safari 内嵌视频播放问题
- php - 几天以来,Imgur API 不再工作了
- statistics - 对三个重复测量二元结果使用哪种分析
- javascript - JavaScript 中 `num[i] = i` 与 `num.push(i)` 的效率
- javascript - Angular 在 IE 和智能电视浏览器中不起作用
- reactjs - 带有 Apollo-Client 和 Redux-Form 的 GraphQL 突变?
- css - 网页的CSS透明背景图片
- ios - 自定义 UIDocumentPickerViewController NavigationBar
- c# - Ziparchive 附加到现有文件
- c++ - 为什么 C++ 需要 std::make_unique 而不是转发的 unique_ptr 构造函数?