Spring 使SFTP出站门通道可用于mput操作

Spring 使SFTP出站门通道可用于mput操作,spring,spring-integration,Spring,Spring Integration,我正在使用spring集成进行SFTP操作。我需要从SFTP的某个位置轮询具有目录结构的文件,还需要将具有目录结构的文件从本地目录放到SFTP的某个位置。我添加了来自mget和mput操作的伪造入站通道适配器。在运行Junit时,在mput操作的目标SFTP位置会生成一些垃圾消息文件。而且,在部署war之后,没有文件被传输到mget本地目录。在服务器中部署war后,mput和mget操作将启动。请告知配置。这个克斯顿是在引用 Sftp-outboundgatewaycontext.xml 根本

我正在使用spring集成进行SFTP操作。我需要从SFTP的某个位置轮询具有目录结构的文件,还需要将具有目录结构的文件从本地目录放到SFTP的某个位置。我添加了来自mget和mput操作的伪造入站通道适配器。在运行Junit时,在mput操作的目标SFTP位置会生成一些垃圾消息文件。而且,在部署war之后,没有文件被传输到mget本地目录。在服务器中部署war后,mput和mget操作将启动。请告知配置。这个克斯顿是在引用

Sftp-outboundgatewaycontext.xml


根本不清楚你在问什么。像垃圾之类的短语是无用的。您应该能够通过打开调试日志记录并跟踪流中的消息来调试此应用程序

MPUT是最终用户操作。入站通道适配器执行此操作的原因是什么?您应该将本地目录作为消息负载发送,以将所有文件放入SFTP。现在您的配置没有意义。

但是,我如何使MPUT操作成为可轮询操作请更具体一点:您将轮询什么?正如我所说:MPUT消息的一个参数是directory。中的MPUT忽略本地目录。因此,如果目录的内容定期更改,轮询器应该生成该目录。嗨,Artem,看看中提到的JUnit u,我已经配置了inboundMgettRecursive通道来接收来自sftp目录的文件。并编写了一个Junit来接收消息中提到SFTP的dir的文件,如以下所示。但是我不知道如何在xml配置文件中设置SFTP目录,我将从中获取文件。如果是MGET,请建议忽略远程目录。您应该在发送消息中指定远程根模式,并使用表达式派生该远程路径模式。
<?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");
    }


}