Announcement Announcement Module
Collapse
No announcement yet.
Exception when connecting to ftp Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Exception when connecting to ftp

    Hello
    I am trying to connect to ftp using spring integration, I found this sample which I modified and updated to do the get only (it was originally doing ls/get and remove). I am getting this exception when I run the code.


    org.springframework.integration.MessagingException : /test/Outbound is not a file
    at org.springframework.integration.file.remote.gatewa y.AbstractRemoteFileOutboundGateway.get(AbstractRe moteFileOutboundGateway.java:304)


    I am trying to read all the files in the ftp when the job runs (basically do a get), my understating I can do this with gateway and it will return a list of files but I get the exception, another question, can I specify the remote directory in the configuration instead of the code?
    here modified code I have.

    <?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-ftp="http://www.springframework.org/schema/integration/ftp"
    xsi:schemaLocation="http://www.springframework.org/schema/integration/ftp http://www.springframework.org/schem...on-ftp-2.1.xsd
    http://www.springframework.org/schema/integration http://www.springframework.org/schem...ntegration.xsd
    http://www.springframework.org/schema/beans http://www.springframework.org/schem...ring-beans.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">

    <!-- <contextroperty-placeholder location="classpath:user.properties"/>-->

    <int:gateway id="gw" service-interface="org.springframework.integration.samples .ftp.ToFtpFlowGateway"
    default-request-channel="toGet"/>

    <bean id="ftpSessionFactory"
    class="org.springframework.integration.ftp.session .DefaultFtpSessionFactory">
    <property name="host" value="test"/>
    <property name="port" value="21"/>
    <property name="username" value="test"/>
    <property name="password" value="test"/>
    </bean>

    <int-ftp:outbound-gateway id="gatewayGET" cache-sessions="false"
    session-factory="ftpSessionFactory"
    request-channel="toGet"
    command="get"
    command-options="-P"
    local-directory="./LOCAL_FTP_TEMP_DIR/gatewayGET"
    filename-pattern="*.xml"
    expression="payload"/>


    </beans>




    Service Interface

    package org.springframework.integration.samples.ftp;

    import java.io.File;
    import java.util.List;

    /**
    * @author Gary Russell
    * @since 2.1
    *
    */
    public interface ToFtpFlowGateway {

    public List<File> lsGetAndRmFiles1(String dir);
    }




    Implemintation


    package org.springframework.integration.samples.ftp;

    import static org.junit.Assert.assertEquals;
    import static org.junit.Assert.assertTrue;

    import java.io.BufferedInputStream;
    import java.io.DataInputStream;
    import java.io.File;
    import java.io.FileInputStream;
    import java.util.List;

    import org.apache.activemq.protobuf.BufferInputStream;
    import org.apache.commons.net.ftp.FTPFile;
    import org.junit.Test;
    import org.springframework.context.ConfigurableApplicatio nContext;
    import org.springframework.context.support.ClassPathXmlAp plicationContext;
    import org.springframework.integration.ftp.session.FtpFil eInfo;

    /**
    * Demonstrates use of the outbound gateway to use ls, get and rm.
    *
    * The previous Test {@link FtpOutboundChannelAdapterSample} was uploading 2 test
    * files:
    *
    * <ul>
    * <li>a.txt</li>
    * <li>b.txt</li>
    * </ul>
    *
    * This test will now retrieves those 2 files and removes them. Instead of just
    * polling the file, the files are instead retrieved and deleted using explicit
    * FTP commands (LS and RM)
    *
    * @author Gary Russell
    * @since 2.1
    *
    */
    public class FtpOutboundGatewaySample {


    @Test
    public void testLsGetRm() throws Exception {
    System.out.println("FtpOutboundGatewaySample.testL sGetRm()");
    ConfigurableApplicationContext ctx = new ClassPathXmlApplicationContext(
    "/config/FtpOutboundGatewaySample-context.xml");
    System.out.println("FtpOutboundGatewaySample.testL sGetRm()2");
    final ToFtpFlowGateway toFtpFlow = ctx.getBean(ToFtpFlowGateway.class);
    System.out.println("FtpOutboundGatewaySample.testL sGetRm()3");


    List<File> reslt = toFtpFlow.lsGetAndRmFiles1("/test/Outbound/");

    System.out.println("FtpOutboundGatewaySample.testL sGetRm() reslt.size() = " +reslt.get(0).getName());


    /*
    for (File rsl : reslt) {
    FileInputStream fileInputStream = new FileInputStream(rsl);
    BufferedInputStream bufferInputStream = new BufferedInputStream(fileInputStream);
    DataInputStream dataInputStream = new DataInputStream(bufferInputStream);

    while (dataInputStream.available() !=0){

    System.out.println("FtpOutboundGatewaySample.testL sGetRm() " + dataInputStream.readLine());
    }
    }
    */

    }

    }

  • #2
    anyone had a chance to look at this issue?

    Comment

    Working...
    X