使SFTP出站门方式可以用于mput操作

时间:2015-01-24 17:11:10

标签: spring spring-integration

我正在使用spring集成进行SFTP操作。我需要从SFTP的某个位置轮询具有目录结构的文件,并将具有目录结构的文件从本地目录放到某个SFTP位置。我已经为mget& amp;添加了假冒入站通道适配器。运行。在运行Junit时,会在mput操作的目标SFTP位置生成一些垃圾邮件文件。并且,在部署了war之后,没有文件被转移到mget本地目录。一旦在服务器中部署了war,就会启动mput和mget操作请告知配置。这个问题是参考 SFTP inbound adapter configuration for multiple remote directory using single adapter and single channel

SFTP-outboundgatewaycontext.xml

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


    <context:property-placeholder order="0"
        location="classpath:/sftpuser.properties" ignore-unresolvable="true" />
    <context:property-placeholder order="1"
        location="classpath:/sftpfile.properties" ignore-unresolvable="true" />
    <bean id="sftpServerConfig" class="com.iux.ieg.sftp.SftpConfigurator" />




    <bean id="sftpSessionFactory"
        class="org.springframework.integration.file.remote.session.CachingSessionFactory">
        <constructor-arg ref="defaultSftpSessionFactory" />
    </bean>

    <bean id="defaultSftpSessionFactory"
        class="org.springframework.integration.sftp.session.DefaultSftpSessionFactory">
        <property name="host" value="${sftp.host}" />
        <property name="port" value="${sftp.port}" />
        <property name="user" value="${sftp.username}" />
        <property name="privateKey" value="${private.keyfile}" />
        <property name="privateKeyPassphrase" value="${passphrase}" />
    </bean>

    <int:channel id="outputmget">
        <int:queue />

    </int:channel>

    <int:channel id="outputmput">
        <int:queue />

    </int:channel>

<int:inbound-channel-adapter channel="inboundMGetRecursive"
    expression="''">
    <int:poller fixed-rate="1000" max-messages-per-poll="10" /> 
</int:inbound-channel-adapter>

<int:inbound-channel-adapter channel="inboundMPutRecursive" expression="''">
    <int:poller fixed-rate="1000" max-messages-per-poll="10" /> 
</int:inbound-channel-adapter>  





    <int:channel id="inboundMGetRecursive" />

    <int-sftp:outbound-gateway session-factory="sftpSessionFactory"
        request-channel="inboundMGetRecursive" command="mget" expression="payload"
        mode="REPLACE" command-options="-R"

        local-directory-expression="@sftpServerConfig.targetLocalDirectory+ #remoteDirectory"

        reply-channel="outputmget">
<!-- local-filename-generator-expression="#remoteFileName.replaceFirst('sftpSource', 'localTarget')" -->

    </int-sftp:outbound-gateway>




    <int:channel id="inboundMPutRecursive" />

    <int-sftp:outbound-gateway session-factory="sftpSessionFactory"
        request-channel="inboundMPutRecursive" command="mput" command-options="-R"
        auto-create-directory="true" filename-pattern="*.txt" expression="payload"
        local-directory="@SftpServerConfig.mPutLocalDir+'/'"
        remote-directory="sftpTarget" reply-channel="outputmput">

    </int-sftp:outbound-gateway>




</beans>

**Javafile:SftpConfigurator.java**

package com.iux.ieg.sftp;



import java.io.File;

/**

 */
public class SftpConfigurator  {





    private volatile File targetSftpDirectory;

    private volatile File sourceLocalDirectory;

    private volatile File targetLocalDirectory;
    private volatile File mPutLocalDir;

    public File getmPutLocalDir() {
        return mPutLocalDir;
    }



    public void setmPutLocalDir(File mPutLocalDir) {
        this.mPutLocalDir = mPutLocalDir;
    }



    public File getTargetLocalDirectory() {
        return targetLocalDirectory;
    }



    public void setTargetLocalDirectory(File targetLocalDirectory) {
        this.targetLocalDirectory = targetLocalDirectory;
    }



    public File getTargetSftpDirectory() {
        return targetSftpDirectory;
    }



    public void setTargetSftpDirectory(File targetSftpDirectory) {
        this.targetSftpDirectory = targetSftpDirectory;
    }



    public File getSourceLocalDirectory() {
        return sourceLocalDirectory;
    }



    public void setSourceLocalDirectory(File sourceLocalDirectory) {
        this.sourceLocalDirectory = sourceLocalDirectory;
    }







    public SftpConfigurator() {
        this.targetSftpDirectory = new File("/u01/IIP/iipuser/Java/test1") ;
        this.sourceLocalDirectory = new File("D:\\sourceforsftp");
        this.targetLocalDirectory = new File("D:\\sftplocalfolder");
        this.mPutLocalDir=new File("D:\\sourceforsftp");
    }


}

2 个答案:

答案 0 :(得分:0)

你所要求的并不清楚。短语喜欢&#34;一些垃圾&#34;没用您应该能够通过打开DEBUG日志记录来调试此应用程序,并通过流跟踪消息。

答案 1 :(得分:0)

MPUT是最终用户操作。 inbound-channel-adapter这种操作的原因是什么?您应该将local directory作为消息payload发送给PUT所有文件到SFTP。现在你的配置没有明确。