spring-boot - 将大量文件加载到 SFTP 问题
问题描述
我有 Spring 集成 sftp 配置
@Bean
public SessionFactory<ChannelSftp.LsEntry> sftpSessionFactory() {
final DefaultSftpSessionFactory factory = new DefaultSftpSessionFactory(false);
factory.setHost(properties.getHost());
factory.setPort(properties.getPort());
factory.setUser(properties.getUser());
factory.setPassword(properties.getPassword());
factory.setAllowUnknownKeys(true);
return factory;
@Bean
@ServiceActivator(inputChannel = "toSftpChannel")
public MessageHandler handler(@Value("${sftp.folder}") final String remoteDirectory) {
final SftpMessageHandler handler = new SftpMessageHandler(sftpSessionFactory());
handler.setRemoteDirectoryExpressionString(remoteDirectory);
handler.setAutoCreateDirectory(true);
return handler;
}
我需要将 10-20 个 xml 文件上传到 SFTP,(每个文件的大小约为 150MB)
主要问题是我收到 SftpException。InputStream 关闭或 Socket 异常。我不能使用 Cashed 会话,因为客户限制了这一点。
另外,我将文件与并行流
Arrays.stream(files)
.parallel()
.forEach(sftpService::uploadFile);
那么,将所有文件上传到 sftp 最安全的方法是什么?
解决方案
通过删除并行流并为每次上传打开每个会话来解决
推荐阅读
- c# - 重新加载实时图表图表只会添加新数据
- c# - 分页样式搞砸了
- node.js - oAuth 2.0 access token validation node.js
- c# - 不区分大小写的 List.Contains():方法“包含”没有重载需要 2 个参数
- django - 获取属性错误:模块'matplotlib.pyplot'没有属性'canvas'
- javascript - GraphQL:在文件上传期间解决承诺时出错
- c# - 覆盖/更新文件夹中的现有图像文件
- javascript - 如何在mysql数据库中插入我的代码JS
- java - 为什么当 tabAt[i] 不为空时 ConcurrentHashMap 不使用“CAS”但使用“同步”
- java - Firebase UI RecyclerView