简体   繁体   English

从 sftp 读取多个文件夹 - Spring Integration & Batch

[英]Read multiple folders from sftp - Spring Integration & Batch

we have spring integration with spring batch application where we process a file from a sftp server using a poller.我们将 spring 与 spring 批处理应用程序集成在一起,我们使用轮询器处理来自 sftp 服务器的文件。 have few questions on spring integration对 Spring 集成有几个问题

 @Bean
public MessageSource<File> fileReadingMessageSource() {
    log.info("Polling for src msg : " + LocalDateTime.now());
    SftpInboundFileSynchronizingMessageSource source =
            new SftpInboundFileSynchronizingMessageSource(sftpInboundFileSynchronizer());
    source.setLocalDirectory(new File("sftp-inbound"));
    source.setAutoCreateLocalDirectory(true);
    return source;
}

@Bean
public SftpInboundFileSynchronizer sftpInboundFileSynchronizer() {
    log.info("Creating sync");
    SftpInboundFileSynchronizer fileSynchronizer = new SftpInboundFileSynchronizer(sftpSessionFactory());
    fileSynchronizer.setDeleteRemoteFiles(true);
    fileSynchronizer.setRemoteDirectory(ftpSrcPath);
    fileSynchronizer.setFilter(new SftpSimplePatternFileListFilter(srcFileName));
    return fileSynchronizer;
}
  1. can we process multiple files from different directory我们可以处理来自不同目录的多个文件吗
  2. need to get the file directory from which folder the file was read from the sftp server需要从sftp服务器读取文件的文件夹中获取文件目录

For the first question I read that mget function will be able to provide that feature but im not getting the right example.对于第一个问题,我读到 mget 函数将能够提供该功能,但我没有得到正确的示例。 pls help on this请帮忙

The SftpInboundFileSynchronizer does not support sub-dirs: SftpInboundFileSynchronizer不支持子目录:

protected boolean isFile(LsEntry file) {
    return (file != null && file.getAttrs() != null && !file.getAttrs().isDir() && !file.getAttrs().isLink());
}

You can configure several channel adapters for the same output channel, but for different sub-dirs.您可以为同一输出通道配置多个通道适配器,但用于不同的子目录。 The remote directory by itself in the FileHeaders.REMOTE_DIRECTORY header. FileHeaders.REMOTE_DIRECTORY标头中的远程目录本身。 You also can use #remoteDirectory SpEL variable in the localFilenameGeneratorExpression option of the SftpInboundFileSynchronizer .您还可以在SftpInboundFileSynchronizerlocalFilenameGeneratorExpression选项中使用#remoteDirectory SpEL 变量。

You also can use a Polling Multiple Servers and Directories approach, but it is a bit complicated: https://docs.spring.io/spring-integration/docs/current/reference/html/sftp.html#sftp-rotating-server-advice您也可以使用轮询多个服务器和目录的方法,但它有点复杂: https ://docs.spring.io/spring-integration/docs/current/reference/html/sftp.html#sftp-rotating-server -建议

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM