【发布时间】:2018-11-29 22:59:58
【问题描述】:
我一直在尝试将SftpInboundFileSynchronizer 与包含子目录的远程目录一起使用,例如 /myfiles/mysubdir/lefile.txt,我设置了一个过滤器来抓取目录中的文件:
mysync.setRemoteDirectory("myfiles/");
mysync.setFilter(new SftpRegexPatternFileListFilter(".*\\.txt$"));
然后是 SftpInboundFileSynchronizingMessageSource 作为我的 InboundChannelAdapter
我已将SftpInboundFileSynchronizingMessageSource 和RecursiveDirectoryScanner 设置为扫描仪,并且我对要检索的文件的深度或数量没有设置限制。我还在扫描仪上设置了FOLLOW_LINKS fileVisitOption 以进行良好的测量。
我只能从 myfiles 路径将文件拉入本地目录,但更深的内容不会复制到本地目录。 我一辈子都想不通是否有什么我没有做。
编辑: 如果我只发送“/”作为目录以使用 mget -R 检查,InboundChannelAdapter 会包含什么?
@Bean
@InboundChannelAdapter(value = "sftpChannel", poller = @Poller(fixedDelay = "10"))
public MessageSource<?> myMessageSource() {
}
@Bean(name = "myGateway")
@ServiceActivator(inputChannel = "sftpChannel")
public MessageHandler handler() {
SftpOutboundGateway gateway =
new SftpOutboundGateway(sftpSessionFactory(), "mget", "'myfiles/*'");
gateway.setOutputChannelName("listSplitter");
gateway.setOptions("-R");
gateway.setAutoCreateLocalDirectory(true);
myLocalPath = Paths.get(myLocalParentDir).toRealPath().toString();
gateway.setLocalDirectory(new File(myLocalPath));
SftpRegexPatternFileListFilter regexFilter = new regexFilter("^.*\\.txt");
regexFilter.setAlwaysAcceptDirectories(true);
regexFilter.setFilter(sftpRegexPatternFileListFilter);
return gateway;
}
【问题讨论】:
-
I am only able to pull files into the local directory from the myfiles path, but anything deeper is not copied to the local dir: 所以如果我理解正确你不能递归地将远程目录复制到本地目录,对吗?如果是,那么您的正则表达式可能不正确。 -
该组件不支持对远程目录的递归;改用网关;详情见我的回答。
-
@MahmoudBenHassine 是的,但从 Gary 的 cmets 看来,该组件不支持,因此将尝试使用网关
标签: spring-integration spring-batch spring-integration-sftp