我需要将文件从本地传输到多个 sftp 服务器文件夹。 到目前为止,这是我的代码,我正在使用单 channel 进行一对一传输:
private IntegrationFlow localToRemotePush(final String localDirectory,String remoteDirectory, String adapterName) {
return IntegrationFlows
.from(Files.inboundAdapter(Paths.get(localDirectory).toFile())
.regexFilter(FILE_PATTERN_REGEX)
.preventDuplicates(false),
e -> {
e.poller(Pollers.fixedDelay(getPollerIntervalMs())
.maxMessagesPerPoll(getMaxFetchSize())
.errorChannel("errorChannel")
.transactional(transactionManager)
.transactionSynchronizationFactory(mmPushSftpSyncFactory()) // moves processed files
).id(adapterName);
})
.handle(Sftp.outboundAdapter(mmPushSftpSessionFactory())
.remoteDirectory(getRemoteRootDir() + remoteDirectory1)
//.remoteDirectory(getRemoteRootDir() + remoteDirectory2) --- this way is correct ?
.temporaryFileSuffix(".tmp"))
.get();
}
是否可以使用单 channel 将本地文件从一个本地文件夹传输到多个 sftp 文件夹?
最佳答案
不,使用单个 Sftp.outboundAdapter()
是不可能的。它仅设计用于单个远程目录,但是可以通过函数或表达式从请求消息中确定该目录。但那是另外一回事了。
您的任务可以通过针对每个远程目录和publishSubscribe
配置的多个Sftp.outboundAdapter()
来实现。像这样:
.publishSubscribeChannel(s -> s
.subscribe(f -> f
.handle(Sftp.outboundAdapter(mmPushSftpSessionFactory())
.remoteDirectory(getRemoteRootDir() + remoteDirectory1)
.temporaryFileSuffix(".tmp")))
.subscribe(f -> f
.handle(Sftp.outboundAdapter(mmPushSftpSessionFactory())
.remoteDirectory(getRemoteRootDir() + remoteDirectory2)
.temporaryFileSuffix(".tmp")))
)
关于java - 具有多个文件夹的 Sftp OutboundAdapter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54204455/