Announcement Announcement Module
Collapse
No announcement yet.
how to use spring-integration sftp to trans folder form remote-directory Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • how to use spring-integration sftp to trans folder form remote-directory

    hi
    in my program, i want to use spring-integration sftp to move folder and files to localDirectory,but I found only files can move, i want to ask how to move folder.
    thanks!

  • #2
    Use an outbound gateway (mget with recursion option -R) - http://docs.spring.io/spring-integra...tbound-gateway

    Recursion was added in Spring Integration 3.0.

    Comment


    • #3
      Thanks for your help. Now i has complete transfer folder ,but there are another problem. In the first time , is's success. but at second time,as the folder exist in the local-directory,it will alert error message the folder is exist,how to deal this. can you give me a example to transfer file or folder from two remote server. thanks!

      Comment


      • #4
        this is my code

        <?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:context="http://www.springframework.org/schema/context"
        xmlns:int="http://www.springframework.org/schema/integration"
        xmlns:int-sftp="http://www.springframework.org/schema/integration/sftp"
        xsi:schemaLocation="http://www.springframework.org/schema/integration http://www.springframework.org/schem...ration-3.0.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schem...ring-beans.xsd
        http://www.springframework.org/schema/integration/sftp http://www.springframework.org/schem...n-sftp-3.0.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">

        <int:gateway id="gwGet" service-interface="org.springframework.integration.samples .sftp1.ToSftpFlowGateway"
        default-request-channel="inbound"/>

        <int:gateway id="gwPut" service-interface="org.springframework.integration.samples .sftp1.ToSftpFlowGateway1"
        default-request-channel="outbound"/>

        <bean id="sftpSessionFactory"
        class="org.springframework.integration.sftp.sessio n.DefaultSftpSessionFactory">
        <property name="host" value="192.168.179.130"/>
        <property name="port" value="22"/>
        <property name="user" value="byw"/>
        <property name="password" value="admin"/>
        </bean>

        <bean id="otherSftpSessionFactory"
        class="org.springframework.integration.sftp.sessio n.DefaultSftpSessionFactory">
        <property name="host" value="192.168.179.130"/>
        <property name="port" value="22"/>
        <property name="user" value="byw"/>
        <property name="password" value="admin"/>
        </bean>

        <int-sftp:outbound-gateway id="gatewayLS"
        session-factory="sftpSessionFactory"
        request-channel="inbound"
        command="ls"
        command-options=""
        expression="payload"
        reply-channel="lschanel"/>

        <int-sftp:outbound-gateway id="gatewayGet"
        request-channel="lschanel"
        session-factory="sftpSessionFactory"
        command="mget"
        local-directory-expression="'s:\\test\\'+#remoteDirectory"
        local-filename-generator-expression="#remoteFileName"
        command-options="-R"
        requires-reply="true"
        expression="headers['file_remoteDirectory'] + '/' + headers['file_remoteFile']"
        />

        <int-sftp:outbound-gateway id="gatewayPut"
        request-channel="outbound"
        session-factory="otherSftpSessionFactory"
        auto-create-directory="true"
        auto-create-local-directory="true"
        command="mput"
        command-options="-R"
        expression="headers['file_remoteDirectory'] + '/' + headers['file_remoteFile']"
        remote-directory="dest/"
        />


        </beans>


        @Test
        public void testLsGetRm() throws Exception {
        ConfigurableApplicationContext ctx = new ClassPathXmlApplicationContext("classpath:integrat ion/SftpOutboundGatewaySample-context.xml");
        ToSftpFlowGateway toFtpFlow = ctx.getBean(ToSftpFlowGateway.class);
        ToSftpFlowGateway1 toFtpFlowout = ctx.getBean(ToSftpFlowGateway1.class);
        try {
        List<Boolean> rmResults = toFtpFlow.lsGetAndRmFiles("source/");
        toFtpFlowout.lsGetAndRmFiles("s:\\test\\");
        } finally {
        ctx.close();
        }
        }
        Last edited by byw_zz; May 29th, 2014, 09:32 AM.

        Comment

        Working...
        X