Java Spring集成:处理后将文件移动到远程SFTP位置
我有一个条件,我应该通过以下步骤从SFTP远程位置读取文件:Java Spring集成:处理后将文件移动到远程SFTP位置,java,spring,spring-integration,Java,Spring,Spring Integration,我有一个条件,我应该通过以下步骤从SFTP远程位置读取文件: 从SFTP位置读取文件,比如说input文件夹 处理该文件并使用该文件的内容调用RESTAPI 如果调用成功,请将远程SFTP文件移动到存档 文件夹else将远程SFTP文件移动到错误文件夹 我正在考虑两种方法。我不知道哪些是可能的 首先,将文件从SFTP远程位置读取到本地,然后从远程位置将其删除。然后调用restapi。根据REST调用的响应,成功或错误地将文件上载到远程文件夹 其次,将文件从SFTP远程位置读取到本地位置。然后调用
input
文件夹存档
文件夹else将远程SFTP文件移动到错误
文件夹<int-sftp:inbound-channel-adapter id="sftpInbondAdapter"
auto-startup="true"
channel="receiveChannel"
session-factory="sftpSessionFactory"
local-directory="${local.dir}"
remote-directory="${sftp.dir.input}"
auto-create-local-directory="true"
delete-remote-files="true"
filename-pattern="*.txt">
<int:poller fixed-rate="60000" max-messages-per-poll="1" />
</int-sftp:inbound-channel-adapter>
<int:channel id="receiveChannel"/>
<int:splitter input-channel="receiveChannel" output-channel="singleFile"/>
<int:channel id="singleFile"/>
<int:service-activator input-channel="singleFile"
ref="sftpFileListenerImpl" method="processMessage" output-channel="costUpdate" />
<int:channel id="costUpdate" />
<int:header-enricher input-channel="costUpdate" output-channel="headerEnriched">
<int:header name="content-type" value="application/json" />
</int:header-enricher>
<int:channel id="headerEnriched" />
<int-http:outbound-gateway
url="${cost.center.add.rest.api}" request-channel="headerEnriched"
http-method="POST" expected-response-type="java.lang.String" reply-channel="costAdded" >
</int-http:outbound-gateway>
<int:publish-subscribe-channel id="costAdded" />
在评估API调用响应后,一旦API调用成功,我想将远程文件移动到远程文件夹中的另一个位置。我的问题是如何根据http:outbound gateway的响应将远程文件移动到另一个远程位置?请参见,特别是-它显示了如何根据上载的成功/失败采取不同的操作
编辑:
回应您对Artem答案的评论;因为您有delete remote files=“true”
所以没有远程文件可移动;您必须首先将其设置为false
然后,使用我建议的建议来处理成功或失败-使用
ftp:outbound gateway
和mv
远程文件。请参见。对不起,您的场景看起来不错。你面临什么问题?删除或不删除远程文件对您来说没有意义,因为默认情况下本地文件都有AcceptOnceFileListFilter
。实际上,在评估API调用响应后,一旦API调用成功,我想将远程文件移到远程文件夹中的另一个位置。我的问题是如何根据http:outbound gateway
的响应将远程文件移动到另一个远程位置?现在已经很清楚了。你以前没有具体说明这个问题。。。Gary的回答适合您吗?在http:outbound gateway
response之后,我如何从singleFile
频道获取文件?根据文件名,如何将sftp位置中的文件从一个文件夹移动到另一个文件夹?我编辑了我的答案;请在以后的提问中尽量具体一些。我可以使用ftp:SFTP上的出站网关吗?可以;这里有一个。一般来说,在提问之前查阅文档是个好主意。谢谢。不过我还有最后一点困惑。我有特定的文件,直到singleFile
频道,在该频道之后,其他后续频道中将不会有文件消息。当远程位置有多个文件时,我如何根据http:outbound gateway
的响应知道从远程文件夹中移动哪个文件?只需将原始文件存储在消息头中即可。此外,您还经常使用