3
votes

I'm using apache camel to make a ftp client for downloading some files to some local directory. The program reads a xml file to get the name of the file that will be fetched from the ftp.The program seems to work except that the files downloaded are corrupted. Right now I'm trying to download some image files but the ones I get are 14.9Kb and corrupted, no error message shown.

This is my code:

main

    public void main() throws FileNotFoundException {
        BasicConfigurator.configure();
        RutaFtp routeBuilder = new RutaFtp();
        CamelContext ctx = new DefaultCamelContext();

        try {
            ctx.addRoutes(routeBuilder);
            ctx.start();
            Thread.sleep(10000);
            ctx.stop();
        }
        catch (Exception e) {
            e.printStackTrace();
        }

    }

camel route:

from("file:./?fileName=Datos.xml&noop=true")
        .split(xpath("//Datos/imagen/text()"))
        .setProperty("rutaArchivo", this.body())
        .log(LoggingLevel.INFO, "imagen: ${body}")
        .process(ExtraerNombre).to("direct:ftp").end(); 

        from("direct:ftp")  
        .pollEnrich("ftp://"+user+"@"+ftp+"/?password="+password+"&recursive=true&passiveMode=true&fileName=${body}&delete="+borrado+"")
        .to("file:C:/outputFolder?flatten=true").end();
    }

I've tried using the streamDownload parameter but tha prevents the files to be downloaded (I don't know why)

.pollEnrich("ftp://"+user+"@"+ftp+"/?password="+password+"&recursive=true&passiveMode=true&streamDownload=true&fileName=${body}&delete="+borrado+"")

console log:

INFO | Apache Camel 2.15.1.redhat-621084 (CamelContext: camel-1) is starting 0 [main] INFO org.apache.camel.impl.DefaultCamelContext - Apache Camel 2.15.1.redhat-621084 (CamelContext: camel-1) is starting INFO | JMX is enabled 10 [main] INFO org.apache.camel.management.ManagedManagementStrategy - JMX is enabled INFO | Loaded 185 type converters 208 [main] INFO org.apache.camel.impl.converter.DefaultTypeConverter - Loaded 185 type converters INFO | AllowUseOriginalMessage is enabled. If access to the original message is not needed, then its recommended to turn this option off as it may improve performance. 395 [main] INFO org.apache.camel.impl.DefaultCamelContext - AllowUseOriginalMessage is enabled. If access to the original message is not needed, then its recommended to turn this option off as it may improve performance. INFO | StreamCaching is not in use. If using streams then its recommended to enable stream caching. See more details at http://camel.apache.org/stream-caching.html 395 [main] INFO org.apache.camel.impl.DefaultCamelContext - StreamCaching is not in use. If using streams then its recommended to enable stream caching. See more details at http://camel.apache.org/stream-caching.html INFO | Endpoint is configured with noop=true so forcing endpoint to be idempotent as well 395 [main] INFO org.apache.camel.component.file.FileEndpoint - Endpoint is configured with noop=true so forcing endpoint to be idempotent as well INFO | Using default memory based idempotent repository with cache max size: 1000 395 [main] INFO org.apache.camel.component.file.FileEndpoint - Using default memory based idempotent repository with cache max size: 1000 INFO | Route: route1 started and consuming from: Endpoint[file://./?fileName=Datos.xml&noop=true] 502 [main] INFO org.apache.camel.impl.DefaultCamelContext - Route: route1 started and consuming from: Endpoint[file://./?fileName=Datos.xml&noop=true] INFO | Route: route2 started and consuming from: Endpoint[direct://ftp] 504 [main] INFO org.apache.camel.impl.DefaultCamelContext - Route: route2 started and consuming from: Endpoint[direct://ftp] INFO | Total 2 routes, of which 2 is started. 504 [main] INFO org.apache.camel.impl.DefaultCamelContext - Total 2 routes, of which 2 is started. INFO | Apache Camel 2.15.1.redhat-621084 (CamelContext: camel-1) started in 0.504 seconds 507 [main] INFO org.apache.camel.impl.DefaultCamelContext - Apache Camel 2.15.1.redhat-621084 (CamelContext: camel-1) started in 0.504 seconds INFO | Created default XPathFactory com.sun.org.apache.xpath.internal.jaxp.XPathFactoryImpl@5434283f 1533 [Camel (camel-1) thread #0 - file://./] INFO org.apache.camel.builder.xml.XPathBuilder - Created default XPathFactory com.sun.org.apache.xpath.internal.jaxp.XPathFactoryImpl@5434283f INFO | imagen: ftp://190.0.56.190:8021/pruebasumman/conductor/71708375.jpg 1635 [Camel (camel-1) thread #0 - file://./] INFO route1 - imagen: ftp://190.0.56.190:8021/pruebasumman/conductor/71708375.jpg INFO | Apache Camel 2.15.1.redhat-621084 (CamelContext: camel-1) is shutting down 10521 [main] INFO org.apache.camel.impl.DefaultCamelContext - Apache Camel 2.15.1.redhat-621084 (CamelContext: camel-1) is shutting down INFO | Starting to graceful shutdown 2 routes (timeout 300 seconds) 10524 [main] INFO org.apache.camel.impl.DefaultShutdownStrategy - Starting to graceful shutdown 2 routes (timeout 300 seconds) INFO | Waiting as there are still 3 inflight and pending exchanges to complete, timeout in 300 seconds. 10524 [Camel (camel-1) thread #2 - ShutdownTask] INFO org.apache.camel.impl.DefaultShutdownStrategy - Waiting as there are still 3 inflight and pending exchanges to complete, timeout in 300 seconds. INFO | Waiting as there are still 3 inflight and pending exchanges to complete, timeout in 299 seconds. 11525 [Camel (camel-1) thread #2 - ShutdownTask] INFO org.apache.camel.impl.DefaultShutdownStrategy - Waiting as there are still 3 inflight and pending exchanges to complete, timeout in 299 seconds. INFO | Waiting as there are still 3 inflight and pending exchanges to complete, timeout in 298 seconds. 12528 [Camel (camel-1) thread #2 - ShutdownTask] INFO org.apache.camel.impl.DefaultShutdownStrategy - Waiting as there are still 3 inflight and pending exchanges to complete, timeout in 298 seconds. INFO | Waiting as there are still 3 inflight and pending exchanges to complete, timeout in 297 seconds. 13529 [Camel (camel-1) thread #2 - ShutdownTask] INFO org.apache.camel.impl.DefaultShutdownStrategy - Waiting as there are still 3 inflight and pending exchanges to complete, timeout in 297 seconds. INFO | Waiting as there are still 3 inflight and pending exchanges to complete, timeout in 296 seconds. 14540 [Camel (camel-1) thread #2 - ShutdownTask] INFO org.apache.camel.impl.DefaultShutdownStrategy - Waiting as there are still 3 inflight and pending exchanges to complete, timeout in 296 seconds. INFO | Waiting as there are still 3 inflight and pending exchanges to complete, timeout in 295 seconds. 15555 [Camel (camel-1) thread #2 - ShutdownTask] INFO org.apache.camel.impl.DefaultShutdownStrategy - Waiting as there are still 3 inflight and pending exchanges to complete, timeout in 295 seconds. INFO | Waiting as there are still 3 inflight and pending exchanges to complete, timeout in 294 seconds. 16568 [Camel (camel-1) thread #2 - ShutdownTask] INFO org.apache.camel.impl.DefaultShutdownStrategy - Waiting as there are still 3 inflight and pending exchanges to complete, timeout in 294 seconds. INFO | Waiting as there are still 3 inflight and pending exchanges to complete, timeout in 293 seconds. 17569 [Camel (camel-1) thread #2 - ShutdownTask] INFO org.apache.camel.impl.DefaultShutdownStrategy - Waiting as there are still 3 inflight and pending exchanges to complete, timeout in 293 seconds. INFO | Waiting as there are still 3 inflight and pending exchanges to complete, timeout in 292 seconds. 18574 [Camel (camel-1) thread #2 - ShutdownTask] INFO org.apache.camel.impl.DefaultShutdownStrategy - Waiting as there are still 3 inflight and pending exchanges to complete, timeout in 292 seconds.

Thanks in advance.

1

1 Answers

4
votes

Download image file in binary mode

By default, Camel FTP is downloading file by ASCII mode.

Add binary=true into your ftp route will turn from ASCII mode to binary mode