Home > Blockchain >  How to trigger and poll an ftp outbound gateway
How to trigger and poll an ftp outbound gateway

Time:03-17

I am trying to transfer files from an ftp server using the ftp outbound gateway with recursive method as my ftp server will generate new random name folder and I need to fetch everything. I only know this method work, unless anyone can suggest easier one. Anyway, this is my code.

@Bean(value = "ftpTolocal")
public IntegrationFlow fileToFile() {
    IntegrationFlow flow = IntegrationFlows
            .from("inputChannel")
            .handle(Ftp.outboundGateway(defaultFtpSessionFactory(),
                    AbstractRemoteFileOutboundGateway.Command.MGET,
                    null)
                    //.regexFileNameFilter("(.*n.txt)")
                    .autoCreateDirectory(true)
                    .options(AbstractRemoteFileOutboundGateway.Option.RECURSIVE)
                    .localDirectoryExpression("'/localDirectory/'   #remoteDirectory"))
            .channel("nullChannel")
            
            .get();
    return flow;
}

I have searched and the answer I always get is to create an inputChannel message but I couldn't find one that actually tells me how to do it. I also see many xml solution, but I couldn't find how to implement it. FTP integration guide seems rare and the explanation seems difficult to understand for a rookie like me. Thanks in advance.

CodePudding user response:

@Bean
IntegrationFlow polled() {
    return IntegrationFlows.fromSupplier(() -> "testMessage",
                    e -> e.poller(Pollers.fixedDelay(Duration.ofSeconds(5))))
            .handle(System.out::println)
            .get();
}
  • Related