在sftp remote中-我有2个[ready]和[process]文件夹,我需要做的是首先将文件从ready移至处理,然后使用单个通道将该文件移至本地目录。 请检查我的代码是否正确? 我的代码可以正常工作,但是我怀疑首先将代码移到远程处理或本地文件夹中吗?
@Bean
public IntegrationFlow remoteToLocal() {
return IntegrationFlows
.from(Sftp.inboundAdapter(sftpSessionFactory())
.remoteDirectory(sftpProperties.getRemoteRootDir() + "/ready")
.regexFilter(FILE_PATTERN_REGEX)
.deleteRemoteFiles(true)
.localDirectory(new File(mmFileProperties.getMcfItes()+ mmFileProperties.getInboundDirectory()))
.preserveTimestamp(true)
.temporaryFileSuffix(".tmp"),
e -> e.poller(Pollers.fixedDelay(sftpProperties.getPollerIntervalMs()))
.id("sftpInboundAdapter"))
.handle(Sftp.outboundAdapter(mmSftpSessionFactory())
.remoteDirectory(sftpProperties.getRemoteRootDir() + "/process")
.temporaryFileSuffix(".tmp"))
.get();
}
请检查新代码,但是它不起作用
private StandardIntegrationFlow remoteToLocalFlow(final String localDirectory, final String remoteDirectoryProcessing, final String adapterName) {
return IntegrationFlows
.from(Sftp.inboundAdapter(mmSftpSessionFactory())
.remoteDirectory(remoteRootDir + remoteDirectoryProcessing)
.regexFilter(FILE_PATTERN_REGEX)
.deleteRemoteFiles(true)
.localDirectory(Paths.get(localDirectory).toFile())
.preserveTimestamp(true)
.temporaryFileSuffix(".tmp"),
e -> {
e.poller(Pollers.fixedDelay(mmSftpProperties.getPollerIntervalMs()))
.id(adapterName);
})
.handle(m -> logger.trace("File received from sftp interface: {}", m))
.handleWithAdapter(h -> h.sftpGateway(sftpSessionFactory(),AbstractRemoteFileOutboundGateway.Command.MV, "payload")
.renameExpression(remoteRootDir + ready)
.localDirectoryExpression(remoteRootDir + process)).get(); }
答案 0 :(得分:0)
看起来不错,但这不是最好的方法;您正在复制文件,将其删除并以其他名称发送回去。
改为使用SftpOutboundGateway
with a MV (move) command。
您还可以使用网关列出和获取文件。