Spring 集成 (SFTP):从子目录下载文件时出现问题

Spring Integration (SFTP): problem with downloading files from subdirectories

我在 Spring 引导应用程序中使用 Spring 集成版本 5.4.4。 我需要从“server_sftp”目录下的子目录中获取所有 XML 文件。为此,我将 SFTP Streaming Inbound Channel Adapter 和 SFTP Outbound Gateway 与 mget 命令结合使用。不幸的是,该应用程序只从根目录(“server_sftp”)下载文件,而不会从子目录下载文件。

我哪里出错了?

@Bean
@InboundChannelAdapter(channel = "downloadXmlFileInputChannel", poller = @Poller(fixedDelay = "300000"))
public MessageSource<InputStream> sftpXmlFileMessageSource() {
    SftpStreamingMessageSource messageSource = new SftpStreamingMessageSource(template());
    messageSource.setRemoteDirectory("server_sftp/");
    return messageSource;
}

@Bean
public IntegrationFlow xmlFilesReadingFlow() {
    return IntegrationFlows
            .from(sftpXmlFileMessageSource(), e -> e.poller(Pollers.fixedDelay(Duration.ofSeconds(5))))
            .handle(Sftp
                    .outboundGateway(template(), Command.MGET, "'server_sftp/*'")
                    .options(Option.RECURSIVE)
                    .autoCreateLocalDirectory(true)
                    .localDirectoryExpression("'../webapps/event_report_app-1.0/xmlFilesLocalDirectory/' + #remoteDirectory")
                    .localFilenameExpression("#remoteFileName.replaceFirst('sftpSource', 'localTarget')"))
            .channel("downloadXmlFileOutputChannel")
            .get();
}

@Bean
public PollableChannel downloadXmlFileInputChannel() {
    return new QueueChannel();
}

@Bean
public DirectChannel downloadXmlFileOutputChannel() {
    return new DirectChannel();
}

directory structure on the sftp server

使用带有递归 MGET 命令的 outbound gateway 来获取完整的树。

Using the mget Command mget retrieves multiple remote files based on a pattern and supports the following options:

-P: Preserve the timestamps of the remote files.

-R: Retrieve the entire directory tree recursively.

-x: Throw an exception if no files match the pattern (otherwise, an empty list is returned).

-D: Delete each remote file after successful transfer. If the transfer is ignored, the remote file is not deleted, because the FileExistsMode is IGNORE and the local file already exists.

The message payload resulting from an mget operation is a List object (that is, a List of File objects, each representing a retrieved file).