1

如何使用 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" />

我试过了,但无法将文件移动到已处理的文件夹。

4

1 回答 1

6

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

<?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>

您的配置问题:

  1. sftpSessionFactoryinbound-channel-adapter. 它应该定义有效负载应转发到的消息通道,因此在您的情况下,它似乎应该是publishToSFTPChannel
  2. publish-subscribe-channel用于代替简单的点对点通道
于 2013-09-24T14:26:20.813 回答