Search code examples
springspring-integrationsftpspring-integration-sftp

SFTP Persistent Accept Only Once filter on sftp gateway


I have this code in which I want to incorporate a SftpPersistentAcceptOnceFileListFilter and I don't know how. The filter should be before retrieving files locally.

@InboundChannelAdapter(value = "sftpMgetInputChannel",
    poller = @Poller(fixedDelay = "5000"))
public String filesForMGET(){
  return "'/tmp/input/remoteDirectory/*'";
}

@Bean
public IntegrationFlow sftpMGetFlow() {
    return IntegrationFlows.from("sftpMgetInputChannel")
            .handleWithAdapter(h -> h.sftpGateway(this.sftpSessionFactory,
             Command.MGET, "payload")
            .options(Option.RECURSIVE)
            .regexFileNameFilter("((\\d{8})|*\\.txt)")
            .localDirectoryExpression("'sftp-inbound/'" + "#remoteDirectory"))
            .handler(messageHandler())
            .get();
}

@Bean
public MessageChannel sftpMgetInboundChannel(){
   return new DirectChannel();
}

@Bean
public MessageHandler messageHandler(){
 return new MessageHandler() { ... }
}

Solution

  • Use a CompositeFileListFilter or ChainFileListFilter with a SftpRegexPatternFileListFilter filter and the SftpPersistentAcceptOnceFileListFilter.

    Construct the filter and use .filter(compositeFilter()).