【发布时间】:2022-08-08 20:26:31
【问题描述】:
我们有一个远程 FTP 服务器,其中有一个文件夹 \"test/\",其中包含某些文本文件。 \"test/\" 文件夹内有另一个子目录 \"archive/\"。
FTP服务器->
-测试/
---abc.txt
---xyz.txt
---档案/
我们可以通过本地目录中的 Spring Integration 流下载所有文本文件。 现在我们正在研究如何在 FTP 服务器本身的文件夹 \"archive\" 中移动远程文本文件,一旦它被下载到本地。
我们正在尝试在这样的 handle() 方法中执行此操作->
@Bean
public IntegrationFlow integrationFlow() {
File localDirectory = new File(\"tmp/\");
FtpInboundChannelAdapterSpec ftpInboundChannelAdapterSpec = Ftp.inboundAdapter(gimmeFactory())
.remoteDirectory(\"test/\")
.autoCreateLocalDirectory(true)
.regexFilter(\".*\\\\.txt$\")
.localDirectory(localDirectory)
.preserveTimestamp(true)
.remoteFileSeparator(\"/\");
return IntegrationFlows.from(ftpInboundChannelAdapterSpec, pc -> pc.poller(pm -> pm.fixedRate(1000, TimeUnit.MILLISECONDS)))
.handle((file, messageHeaders) -> {
messageHeaders.forEach((k, v) -> System.out.println(k + \':\' + v));
return null;
})
.handle(Ftp.outboundGateway(gimmeFactory(), AbstractRemoteFileOutboundGateway.Command.MV, \"\'test/archive\'\"))
.get();
}
但它没有移动到远程“存档”文件夹位置。 我们不太确定如何以任何其他方式处理此操作。 我们可以做些什么来修复上面的代码 sn-p 或做一些不同的事情来实现我们想要的吗? 请指教。
更新
谢谢加里的指点。
我能够通过按照以下代码 sn-p-> 中给出的方式解决问题
@Bean
public IntegrationFlow integrationFlow() {
File localDirectory = new File(\"tmp/\");
FtpInboundChannelAdapterSpec ftpInboundChannelAdapterSpec = Ftp.inboundAdapter(gimmeFactory())
.remoteDirectory(\"test/\")
.autoCreateLocalDirectory(true)
.regexFilter(\".*\\\\.txt$\")
.localDirectory(localDirectory)
.preserveTimestamp(true)
.remoteFileSeparator(\"/\");
return IntegrationFlows
.from(ftpInboundChannelAdapterSpec, e -> e.poller(Pollers.fixedDelay(Duration.ofSeconds(5))))
.handle(Ftp.outboundGateway(gimmeFactory(), AbstractRemoteFileOutboundGateway.Command.LS, \"\'test/\'\")
.options(AbstractRemoteFileOutboundGateway.Option.NAME_ONLY))
.split()
.handle(Ftp.outboundGateway(gimmeFactory(), AbstractRemoteFileOutboundGateway.Command.MV, \"\'test/\' +payload\").renameExpression(\"\'test/archive/\' +payload\"))
.channel(\"nullChannel\")
.get();
}
标签: spring-integration spring-integration-dsl spring-integration-ftp