【问题标题】:spring integration sftp not able to move file to processed in remote folderspring integration sftp 无法将文件移动到远程文件夹中处理
【发布时间】:2013-10-01 02:26:31
【问题描述】:

我可以将文件从远程机器复制到本地,但无法将文件移动到远程服务器中的已处理文件夹。

<bean id="sftpSessionFactory" class="org.springframework.integration.sftp.session.DefaultSftpSessionFactory">
<property name="host" value="test.com"/>
<property name="user" value="test"/>
<property name="password" value="test123"/>
<property name="port" value="22"/>
</bean>

<int:publish-subscribe-channel id="publishToSFTPChannel" />

<sftp:inbound-channel-adapter local-directory="#{articlesLocalDirectory}"  filename-pattern="*.xml"  channel="publishToSFTPChannel" session-factory="sftpSessionFactory" remote-directory="#{articlesRemoteDirectory}">
<int:poller fixed-rate="12000"/>
</sftp:inbound-channel-adapter>


<file:outbound-channel-adapter id="moveProcessedFile"
session-factory="sftpSessionFactory" 
channel="publishToSFTPChannel"
directory="#{articlesRemoteDirectory}/processed"
delete-source-files="true"  />

我无法将文件移动到远程 ftp 中的已处理文件夹

【问题讨论】:

  • 你想达到什么目的?您想将文件从 SFTP 服务器下载到本地目录,然后将相同的文件移动到同一 SFTP 服务器上的另一个目录?您的配置不适用于此。您有文件出站适配器,它只会将文件复制到本地目录,而不是远程目录,并且您不需要session-factory。请准确描述您要做什么,因为您在问题中陈述的内容和我在配置中看到的内容是不同的。
  • @Dmitry 再次感谢。我想要实现的是我想将文件从 FTP 复制到本地目录。复制该文件后,我需要将 FTP 中的文件移动到同一远程目录中的已处理文件夹。

标签: spring sftp spring-integration


【解决方案1】:

请通过此链接:

http://publib.boulder.ibm.com/infocenter/wmbhelp/v6r1m0/index.jsp?topic=%2Fcom.ibm.etools.mft.doc%2Fac55462_.htm 可能有助于在远程服务器上移动文件...

【讨论】:

  • 我在 spring 集成中需要 sftp
【解决方案2】:

如果您需要重命名远程机器上的文件,upcoming 3.0 release 现在在 (s)ftp 出站网关上有一个mv 命令。

【讨论】:

    【解决方案3】:

    我同意 Gary Russell 的观点,即最好的方法是使用 mv 命令。但是如果你想使用当前版本,你可以尝试类似这样的配置:

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:int="http://www.springframework.org/schema/integration"
       xmlns:sftp="http://www.springframework.org/schema/integration/sftp"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
            http://www.springframework.org/schema/beans/spring-beans.xsd
            http://www.springframework.org/schema/integration
            http://www.springframework.org/schema/integration/spring-integration.xsd
            http://www.springframework.org/schema/integration/sftp
            http://www.springframework.org/schema/integration/sftp/spring-integration-sftp-2.2.xsd">
    
    <bean id="sftpSessionFactory" class="org.springframework.integration.sftp.session.DefaultSftpSessionFactory">
        <property name="host" value="localhost"/>
        <property name="user" value="user01"/>
        <property name="password" value="abc123"/>
        <property name="port" value="990"/>
    </bean>
    
    <int:channel id="sftpChannel"/>
    
    <sftp:inbound-channel-adapter local-directory="/tmp/test" filename-pattern="*.xml"
                                  channel="sftpChannel" session-factory="sftpSessionFactory"
                                  remote-directory="/">
        <int:poller fixed-rate="5000"/>
    </sftp:inbound-channel-adapter>
    
    <sftp:outbound-channel-adapter channel="sftpChannel" session-factory="sftpSessionFactory"
                                   remote-directory="/processed"/>
    
    </beans>
    

    inbound-channel-adapter 将文件从 SFTP 服务器下载到本地目录,outbound-channel-adapter 将该文件的副本放在 SFTP 服务器上的 /processed 文件夹中。

    请注意,这绝对不是最佳选择,因为您必须将文件重新上传到 SFTP。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-04-11
      • 1970-01-01
      • 1970-01-01
      • 2018-09-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-11-28
      相关资源
      最近更新 更多