【问题标题】:spring integratoin ftp how to send files to different sub-foldersspring集成ftp如何将文件发送到不同的子文件夹
【发布时间】:2017-08-22 02:24:10
【问题描述】:

我已经使用以下配置将所有本地文件发送到目标 ftp 服务器文件夹:

@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;
}

现在我需要将每个文件保存在一个目录结构中作为本地文件。

例如

/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

我该怎么做呢,我

【问题讨论】:

    标签: spring-integration spring-integration-sftp


    【解决方案1】:

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

    不要使用LiteralExpression,即,呃...文字。

    改为使用:

    new SpelExpressionParser().parseExpression(rdExpression)
    

    rdExpression 类似于...

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

    【讨论】:

    • 嗨@Garry,我尝试使用payload.absolutePath,但我得到了ioexception,它说无法写入路径。服务器回复:553 /base/b/b.txt.writing: No such file or directory.
    • 现在我已经解决了路径问题,我需要的是 'auto-create-directory' 的 java config 版本,我需要将其设置为 true !但我不知道如何。 ..
    • handler.setAutoCreateDirectory(true) - 见the javadocs
    猜你喜欢
    • 2023-03-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多