在FTP出站网关中,如何在“mv”命令中获取原始文件名?

问题描述 投票:0回答:1

首先,我列出了一个工作正常的目录中的文件。列出后,我想将文件移动到另一个也可以工作的目录。但是,保留原始文件名是行不通的。这是我的代码;

@Bean(value = "moveFile")
public IntegrationFlow moveFile() {
    IntegrationFlow flow = IntegrationFlows
            .fromSupplier(() -> "/", e -> e.poller(Pollers.fixedDelay(Duration.ofSeconds(5))))
            .handle(Ftp.outboundGateway(sf(), AbstractRemoteFileOutboundGateway.Command.LS, null)
                    .regexFileNameFilter("(dir1|dir2|.*[0-9]|.*.txt)")
                    .options(AbstractRemoteFileOutboundGateway.Option.NAME_ONLY,
                            AbstractRemoteFileOutboundGateway.Option.RECURSIVE))
            .split()
            .handle(Ftp.outboundGateway(sf(), AbstractRemoteFileOutboundGateway.Command.MV, null)
                    .renameExpression("'/newdirectory/' + #remoteFileName"))
            .channel("nullChannel")
            .get();
    return flow;
}

#remoteFileName 在这里不起作用,但当我在 mget 命令中使用它时可以起作用,并且也无需经过另一个出站。 headers['file_relativePath'] 和 headers['file_remoteFile'] 也不起作用,这是我搜索的一些结果。

如果您不介意的话,还有一个额外的问题, (dir1|dir2|.[0-9]|..txt) 正则表达式对我有用,但那是因为 .*[0-9] 适用于我的所有文件夹根据其命名方式在该目录中。我真正想要的是那里的任何文件夹的表达。

提前致谢。

更新

我设法解决了它。 SpEL变量是'payload',它是原始文件目录和文件名的字符串。

IntegrationFlow flow = IntegrationFlows
            .fromSupplier(() -> "/", e -> e.poller(Pollers.fixedDelay(Duration.ofSeconds(5))))
            
            .handle(Ftp.outboundGateway(sf(), AbstractRemoteFileOutboundGateway.Command.LS, null)
                    .regexFileNameFilter("(dir1|dir2|.*[0-9]|.*.txt)")
                    .options(AbstractRemoteFileOutboundGateway.Option.RECURSIVE,AbstractRemoteFileOutboundGateway.Option.NAME_ONLY))
            .split()
            .handle(Ftp.outboundGateway(sf(), AbstractRemoteFileOutboundGateway.Command.MV, null)
                    .renameExpression("'/newdirectory/' + payload"))
            .channel("nullChannel")
            .get();
    return flow;
spring ftp spring-integration spring-integration-dsl
1个回答
0
投票

#remoteFileName
是使用 MGET 命令生成本地文件的上下文中远程文件的 SpEL 变量。

MV
命令没有远程文件的上下文。它仅适用于一个远程文件。您可以在请求消息中提供所有必要的信息:有效负载及其标头。然后您可以在该
payload
中使用它们的
headers
renameExpression
属性。

在文档中查看更多信息:https://docs.spring.io/spring-integration/docs/current/reference/html/ftp.html#using-the-mv-command

© www.soinside.com 2019 - 2024. All rights reserved.