Spring Integration FTP:下载完成后移动远程文件至远程归档目录
问题:Spring Integration FTP文件下载后,无法移动远程文件到归档目录
远程FTP服务器目录结构如下:
- test/
- abc.txt
- xyz.txt
- archive/
我们已经通过Spring Integration流将test/下的所有文本文件下载到本地目录,现在需要在文件下载完成后,把远程FTP服务器上的这些文本文件移动到test/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(); }
但执行后,远程文件并未移动到test/archive/目录中。请问如何修复上述代码,或者提供其他可行的实现方案?
更新:问题已解决
感谢指导,通过以下代码实现了需求:
@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(); }
内容的提问来源于stack exchange,提问作者Wolf17
相关产品推荐
相关产品推荐

