sftp的Spring集成

sftp的Spring集成,spring,sftp,spring-integration,Spring,Sftp,Spring Integration,如何使用SFTP适配器将文件从本地系统移动到远程FTP。我正在浏览这些示例,所有这些示例都提到了将文件从远程FTP复制到本地计算机 我需要将文件从本地计算机移动到远程系统文件夹 <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

如何使用SFTP适配器将文件从本地系统移动到远程FTP。我正在浏览这些示例,所有这些示例都提到了将文件从远程FTP复制到本地计算机

我需要将文件从本地计算机移动到远程系统文件夹

<?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:int-sftp="http://www.springframework.org/schema/integration/sftp"
xmlns:file="http://www.springframework.org/schema/integration/file"
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
    http://www.springframework.org/schema/integration/file
    http://www.springframework.org/schema/integration/file/spring-integration-file-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"/>

<file:inbound-channel-adapter directory="#{T(System).getProperty('java.io.tmpdir')}" id="fileInbound"
                          channel="sftpChannel" filename-pattern="*.xml">
<int:poller fixed-rate="1000" max-messages-per-poll="100"/>
</file:inbound-channel-adapter>

<int-sftp:outbound-channel-adapter id="sftpOutboundAdapter" session-factory="sftpSessionFactory"
                               channel="sftpChannel" charset="UTF-8" remote-directory="/"
                               remote-file-separator="/"/>

</beans>

<file:outbound-channel-adapter id="moveProcessedFile"
    channel="sftpChannel"
    directory="file:#{configurationService.configuration.getProperty('acal.jde.publish.folder')}/processed"
    delete-source-files="true" order="2" />


我尝试了此操作,但无法将文件移动到已处理文件夹。

这是基于您的配置,我实际检查该配置是否有效,您可以将其用作起点

<?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:int-sftp="http://www.springframework.org/schema/integration/sftp"
   xmlns:file="http://www.springframework.org/schema/integration/file"
   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
        http://www.springframework.org/schema/integration/file
        http://www.springframework.org/schema/integration/file/spring-integration-file-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"/>

<file:inbound-channel-adapter directory="#{T(System).getProperty('java.io.tmpdir')}" id="fileInbound"
                              channel="sftpChannel" filename-pattern="*.xml">
    <int:poller fixed-rate="1000" max-messages-per-poll="100"/>
</file:inbound-channel-adapter>

<int-sftp:outbound-channel-adapter id="sftpOutboundAdapter" session-factory="sftpSessionFactory"
                                   channel="sftpChannel" charset="UTF-8" remote-directory="/"
                                   remote-file-separator="/"/>

</beans>

配置问题:

  • 您使用
    sftpSessionFactory
    作为
    入站频道适配器中的频道。它应该定义有效负载应转发到的消息通道,因此在您的情况下,它应该是
    publishToSFTPChannel
  • publish-subscribe频道
    代替简单的点对点频道

  • 这是基于您的配置,我实际检查它是否正常工作,您可以使用它作为起点

    <?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:int-sftp="http://www.springframework.org/schema/integration/sftp"
       xmlns:file="http://www.springframework.org/schema/integration/file"
       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
            http://www.springframework.org/schema/integration/file
            http://www.springframework.org/schema/integration/file/spring-integration-file-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"/>
    
    <file:inbound-channel-adapter directory="#{T(System).getProperty('java.io.tmpdir')}" id="fileInbound"
                                  channel="sftpChannel" filename-pattern="*.xml">
        <int:poller fixed-rate="1000" max-messages-per-poll="100"/>
    </file:inbound-channel-adapter>
    
    <int-sftp:outbound-channel-adapter id="sftpOutboundAdapter" session-factory="sftpSessionFactory"
                                       channel="sftpChannel" charset="UTF-8" remote-directory="/"
                                       remote-file-separator="/"/>
    
    </beans>
    
    
    
    配置问题:

  • 您使用
    sftpSessionFactory
    作为
    入站频道适配器中的频道。它应该定义有效负载应转发到的消息通道,因此在您的情况下,它应该是
    publishToSFTPChannel
  • publish-subscribe频道
    代替简单的点对点频道

  • 您只需
    出站通道适配器
    即可将文件放入SFTP。您使用什么将有效负载放入
    inputChannel
    ?顺便说一句,您可以看到通过SFTP@Dmitry将文件放入远程目录的示例,所以我只需要定义出站通道适配器?如果是,我如何配置需要拾取文件的本地文件夹?您没有在出站通道适配器中指定此项,您只指定输入通道。如何将数据放入该通道取决于您:例如,您可以创建一个链,该链将读取本地目录并将有效负载写入
    inputChannel
    ,或者您可以读取文件并将其手动放入玉米作业中的有效负载,以及许多其他选项,您应该决定哪一个最适合您。在我上面给你的链接中,MessageChannel.send
    被显式调用,频道实例从应用程序上下文中获取-这也是一个选项。@Dmitry感谢您的输入。我添加了频道并读取了文件,然后调用outbound-channel-adapter.edit上面的配置,但文件仍然没有移动。您能帮我一下吗?您只需要
    出站通道适配器
    就可以将文件放入SFTP。您使用什么将有效负载放入
    inputChannel
    ?顺便说一句,您可以看到通过SFTP@Dmitry将文件放入远程目录的示例,所以我只需要定义出站通道适配器?如果是,我如何配置需要拾取文件的本地文件夹?您没有在出站通道适配器中指定此项,您只指定输入通道。如何将数据放入该通道取决于您:例如,您可以创建一个链,该链将读取本地目录并将有效负载写入
    inputChannel
    ,或者您可以读取文件并将其手动放入玉米作业中的有效负载,以及许多其他选项,您应该决定哪一个最适合您。在我上面给你的链接中,MessageChannel.send
    被显式调用,频道实例从应用程序上下文中获取-这也是一个选项。@Dmitry感谢您的输入。我添加了频道并读取了文件,然后调用outbound-channel-adapter.edit上面的配置,但文件仍然没有移动。你能帮我一下吗?谢谢,这对我有效,然后我尝试将文件移动到已处理文件夹,但无法将文件移动到已处理文件夹。请查看我的配置。我想你最好每次创建另一个问题,不要修改现有的问题。有多种方法可以处理此问题
    sftpChannel
    现在是直接频道,因此只有一个消费者可以使用它。例如,您可以创建拆分器或路由器,将消息放入每个适配器的不同通道。另外,
    publish-subscribe-channel
    现在实际上可能对您有用-您可以读取本地文件,然后它将作为有效负载发送到SFTP和文件出站适配器。是int:channel id=“sftpChannel”默认值还是我可以使用int:channel id=“\u rd”谢谢它为我工作,然后我尝试将文件移动到已处理文件夹,但无法将文件移动到文件夹。请查看我的配置。我认为您最好每次创建另一个问题,不要修改现有的问题。有多种方法可以处理此问题
    sftpChannel
    现在是直接频道,因此只有一个消费者可以使用它。例如,您可以创建拆分器或路由器,将消息放入每个适配器的不同通道。另外,
    publish-subscribe-channel
    现在实际上可能对您很有用-您可以读取本地文件,然后它将作为有效负载发送到SFTP和文件出站适配器。是int:channel id=“sftpChannel”默认值还是我可以使用int:channel id=“\u-rd”