jony.buzz
jony.buzz

Reputation: 183

Spring integration FTP recursively read files with java DSL

I want to configure a gateway with Java DSL to read all the files from a FTP server recursively, because they are in different folders.

How can I do it? I´ll apreciate code examples please

Upvotes: 2

Views: 775

Answers (1)

Artem Bilan
Artem Bilan

Reputation: 121382

Something like this:

    @Bean
    public FtpOutboundGatewaySpec ftpOutboundGateway() {
        return Ftp.outboundGateway(this.ftpSessionFactory,
                AbstractRemoteFileOutboundGateway.Command.MGET, "payload")
                .options(AbstractRemoteFileOutboundGateway.Option.RECURSIVE)
                .regexFileNameFilter("(subFtpSource|.*1.txt)")
                .localDirectoryExpression("@ftpServer.targetLocalDirectoryName + #remoteDirectory")
                .localFilenameExpression("#remoteFileName.replaceFirst('ftpSource', 'localTarget')");
    }

    @Bean
    public IntegrationFlow ftpMGetFlow(AbstractRemoteFileOutboundGateway<FTPFile> ftpOutboundGateway) {
        return f -> f
                .handle(ftpOutboundGateway)
                .channel(remoteFileOutputChannel());
    }

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

The copy/paste from the project's test-cases.

Upvotes: 1

Related Questions