Search code examples
recursionspring-integrationspring-integration-sftp

The log is polluted by WARN messages: "File name pattern must be '*' when using recursion"


I am using Spring Integration (version 5.4.4) in a Spring Boot application to recursively download files from an sftp server. For this I use SFTP Outbound Gateway with mget command and regex file name filter:

@Bean
public IntegrationFlow jsonFilesReadingFlow() {
    String JSON_FILE_REGEX = "...";
    return IntegrationFlows
            .from("sftp_server")
            .handle(Sftp
                    .outboundGateway(sftpSessionFactory(), Command.MGET, "payload")
                    .options(Option.RECURSIVE)
                    .regexFileNameFilter(JSON_FILE_REGEX)
                    .filter(new SftpPersistentAcceptOnceFileListFilter(new SimpleMetadataStore(), "Downloaded_json_file:"))
                    .autoCreateLocalDirectory(true)
                    .localDirectoryExpression("'/${catalina.base}/webapps/app/WEB-INF/classes/temporaryJsonFilesDirectory'")
                    .localFilenameExpression("#remoteFileName.replaceFirst('sftpSource', 'localTarget')"))
            .channel("downloadJsonFileOutputChannel")
            .get();
}

Unfortunately, each time the sftp server is checked in the application log, an entry is made: "[WARN] 2021-07-06 08:56:21 [scheduling-1] org.springframework.core.log.LogAccessor - File name pattern must be '*' when using recursion "

screenshot - application log

Unfortunately, I cannot cope with solving this problem - do you have any ideas?


Solution

  • The expression for remote file path (payload in your case) must evaluate to something what should ends up with *, e.g. remoteDir/*. All file names from the tree has to be transferred. Only after that your file list filter has an affect.

    See note in the docs: https://docs.spring.io/spring-integration/docs/current/reference/html/sftp.html#using-the-mget-command