Search code examples
spring-integrationspring-integration-sftp

spring integratoin ftp how to send files to different sub-folders


I've managed to send all local files to the target ftp server folder with following config:

@Bean
@ServiceActivator(inputChannel = FtpDef.FTP_OUTBOUND_CHANNEL)
public MessageHandler handler() {
    FtpMessageHandler handler = new FtpMessageHandler(ftpSessionFactory());
    handler.setRemoteDirectoryExpression(
            // only one path can be set here 
            new LiteralExpression("/path/on/ftp/"));
    return handler;
}

now I need each file saved in a directory structure as the local.

e.g.

/base/a/a.txt  =>  /path/on/ftp/a/a.txt
/base/a/aa.txt  =>  /path/on/ftp/a/aa.txt

/base/b/b.txt  =>  /path/on/ftp/b/b.txt
/base/b/bb.txt  =>  /path/on/ftp/b/bb.txt

how can I accomplish that, I


Solution

  • new LiteralExpression("/path/on/ftp/")

    Don't use a LiteralExpression, which is, er... literal.

    Instead, use:

    new SpelExpressionParser().parseExpression(rdExpression)
    

    Where rdExpression is something like...

    "'/path/on/ftp/' + payload.absolutePath"