我尝试使用以下方法删除sftp远程文件夹中的过期文件:
<int-sftp:outbound-gateway
session-factory="sftpSessionFactory"
request-channel="rmChannel"
reply-channel="sftpOutputChannel"
remote-file-separator="/"
command="rm"
expression="headers['file_remoteDirectory'] + headers['file_remoteFile']">
<int-sftp:request-handler-advice-chain>
<si:retry-advice />
</int-sftp:request-handler-advice-chain>
</int-sftp:outbound-gateway>
在进入网关之前,有一个过滤器只能选择过时的文件:
@Override
@Filter
public boolean accept(Message<?> message) {
if (message.getPayload() instanceof FileInfo) {
final FileInfo fileInfo = (FileInfo) message.getPayload();
final DateTime lastModified = new DateTime(fileInfo.getModified());
boolean accept = lastModified.plusDays(this.days).isBeforeNow();
return accept;
}
return false;
}
问题是:
答案 0 :(得分:0)
FileHeaders.REMOTE_FILE
以及FileHeaders.REMOTE_DIRECTORY
由prducing
组件自动创建。由于您要手动删除远程文件,因此您还必须手动指定这些标头。或者使用任何其他属性在expression
中构建要删除的远程路径。
另一个你的问题不清楚。
我刚刚测试过,当没有要删除的远程文件时就结束了这个:
org.springframework.core.NestedIOException: Failed to remove file.; nested exception is 2: /junk
at org.springframework.integration.sftp.session.SftpSession.remove(SftpSession.java:83)
...
Caused by: 2: /junk
at com.jcraft.jsch.ChannelSftp.throwStatusError(ChannelSftp.java:2846)
at com.jcraft.jsch.ChannelSftp.rm(ChannelSftp.java:1958)
at org.springframework.integration.sftp.session.SftpSession.remove(SftpSession.java:79)
因此,如果不删除任何内容,则会抛出异常。
请详细说明当您尝试删除不存在的删除文件时,您的程序无法停止或者还会发生什么。