복붙노트

[SPRING] sftp 용 스프링 통합

SPRING

sftp 용 스프링 통합

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

나는 이것을 시도했지만 처리 된 폴더로 파일을 이동할 수 없습니다.

해결법

  1. ==============================

    1.실제로 작동하는 것으로 확인한 구성을 기반으로 구성되어 있으므로 시작 지점으로 사용할 수 있습니다.

    실제로 작동하는 것으로 확인한 구성을 기반으로 구성되어 있으므로 시작 지점으로 사용할 수 있습니다.

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

    구성 관련 문제 :

  2. from https://stackoverflow.com/questions/18981429/spring-integration-for-sftp by cc-by-sa and MIT license