【问题标题】:How to move files to Folder using spring Integation SFTP Gateway?如何使用 spring Integration SFTP Gateway 将文件移动到文件夹?
【发布时间】:2016-04-11 14:40:15
【问题描述】:

要求:我们正在尝试实现一个应用程序,其功能是使用 spring sftp 出站网关通过 sftp 将文件从入站文件夹移动到进程文件夹。我们已经实现了 sftp 出站网关,如下所示。当我们执行应用程序时,它什么也没给出,即既没有异常也没有预期的输出(即文件没有在 sftp 上移动)

<int-sftp:outbound-gateway id="remoteftpLS"
    session-factory="defaultSftpSessionFactory" request-channel="sftpRequestChannel"
    filename-regex=".*\.txt$" command="mv" expression="'/tmp/datlaa'"
    rename-expression="'/tmp/datlaa/archive'"  />

我想将 *.txt 文件从 '/tmp/datlaa 移动到 /tmp/datlaa/archive。

您能否从我这边提出任何配置错误。或者如何让它发挥作用?

谢谢

添加应用程序上下文文件 http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/integrationhttp://www.springframework.org/schema/integration/spring-integration.xsd http://www.springframework.org/schema/integration/sftphttp://www.springframework.org/schema/integration/sftp/spring-integration-sftp.xsd">

【问题讨论】:

    标签: spring-integration sftp


    【解决方案1】:

    MV 命令处理单个文件:

    mv 命令没有选项。

    表达式属性定义“from”路径,rename-expression 属性定义“to”路径。默认情况下,重命名表达式是 headers['file_renameTo']。此表达式的计算结果不得为 null 或空字符串。如有必要,将创建所需的任何远程目录。结果消息的有效负载为 Boolean.TRUE。原始远程目录在 file_remoteDirectory 标头中提供,文件名在 file_remoteFile 标头中提供。新路径位于 file_renameTo 标头中。

    Spring Integration Reference Manual

    您的filename-regex 在那里被忽略,expressionrename-expression 都应该指向目标文件。

    如果您想处理大量文件,例如使用filename-regex 指定,请考虑使用SFTP LS Gateway -&gt; Spliter -&gt; SFTP MV Gateway

    【讨论】:

    • 这不是 Spring 集成的限制,SFTP 不支持重命名命令中的通配符。
    • 感谢 Artem 和 Gary 的回复。我们已经通过了上面的cmets,然后尝试实现实际需求。即,从 sftp 读取文件,然后通过 sftp 将相同的文件移动到存档文件夹。为此,我们在上下文文件中完成了以下配置,但文件仍然没有移动。除了配置文件,我们还有一个 java 主类,它只加载上下文文件。您能否建议我们是否需要更改配置/在 java 类中添加任何代码。
    • Java Class 'public class SftpGatewaySample { private static Logger logger = Logger.getLogger(SftpGatewaySample.class); public static void main(String[] args) { ApplicationContext context = new ClassPathXmlApplicationContext("outboundGateway.xml");'
    • application-context.xml
    • 您应该将配置注释移动到您的问题中作为编辑。
    猜你喜欢
    • 2013-10-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多