2013-09-24 3 views
1

Как перенести файл из локальной системы на удаленный FTP с помощью SFTP-адаптера. Я просматриваю примеры, и все они упоминают, чтобы скопировать файлы с удаленного FTP на локальный компьютер.Весенняя интеграция для sftp

Мне нужно переместить файлы с локального компьютера в удаленную системную папку.

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

Я пробовал это, но не смог переместить файл в обработанную папку.

+0

Вам нужно только 'исходящих -channel-adapter', чтобы поместить файл в SFTP. Что вы используете, чтобы поместить свою полезную нагрузку в 'inputChannel'? –

+0

Кстати, вы действительно можете увидеть пример, который помещает файл в удаленный каталог через SFTP [здесь] (https://github.com/spring-projects/spring-integration-samples/blob/master/basic/sftp/src/test /java/org/springframework/integration/samples/sftp/SftpOutboundTransferSample.java) –

+0

@Dmitry Итак, мне нужно определить только адаптер исходящего канала? if so Как настроить локальную папку, где нужно выбрать файл? – sree

ответ

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. используется sftpSessionFactory как канал в inbound-channel-adapter. Он должен определить канал сообщений, к которому полезная нагрузка должна быть направлена, так что в вашем случае это, кажется, что это должно быть publishToSFTPChannel
  2. publish-subscribe-channel вместо простого канала точка-точка
+0

Спасибо, что это сработало для меня. Затем я попытался переместить файлы в обработанную папку и не смог переместить файлы в папку. Возможно, вы посмотрите на мою конфигурацию. – sree

+1

Думаю, вам лучше каждый раз задавать другой вопрос, а не изменять существующий. Есть несколько способов справиться с этим. 'sftpChannel' - прямой канал, поэтому только один потребитель может его использовать. Вы можете, например, создать сплиттер или маршрутизатор, чтобы отправить вам сообщение по разным каналам для каждого адаптера. Кроме того, «publish-subscribe-channel» действительно может быть вам полезен сейчас - вы можете прочитать локальный файл, а затем он будет отправлен в качестве полезной нагрузки как для SFTP, так и для исходящих адаптеров файлов. –

Смежные вопросы