0

I am trying to download files from remote server to local directory over SFTP using a fairly simple route.

The problem i am facing is that the route is able to download small files (200 bytes) but gets stuck exactly at 98265 bytes for larger files (200 KB). After around 30 seconds i get a Pipe Closed error.

I am using Apache Camel version: 2.15.3

From: sftp://xxx.xxx.xxx.xxx:xx//User/User01?delay=30s&include=File.*.csv&initialDelay=1m&password=xxxxxx&stepwise=false&streamDownload=true&username=User01

To: file:///var/opt/myfolder/incoming?doneFileName=${file:name}.done

DEBUG 04/11/15 07:45:24,183 org.apache.camel.component.file.FileOperations :Using InputStream to write file: /var/opt/myfolder/incoming/File01.csv 
... 
few seconds gap 
... 
INFO 04/11/15 07:49:53,820 org.apache.camel.component.file.remote.SftpOperations$JSchLogger :JSCH -> Caught an exception, leaving main loop due to Connection reset 
INFO 04/11/15 07:49:53,821 org.apache.camel.component.file.remote.SftpOperations$JSchLogger :JSCH -> Disconnecting from xxx.xxx.xxx.xxx port xx 
WARN 04/11/15 07:49:53,823 org.apache.camel.util.IOHelper :Cannot close: File01.csv. Reason: Pipe closed 
java.io.IOException: Pipe closed 
        at java.io.PipedInputStream.read(PipedInputStream.java:308) 
        at java.io.PipedInputStream.read(PipedInputStream.java:378) 
        at java.io.InputStream.skip(InputStream.java:222) 
        at com.jcraft.jsch.ChannelSftp.skip(ChannelSftp.java:2894) 
        at com.jcraft.jsch.ChannelSftp.access$600(ChannelSftp.java:36) 
        at com.jcraft.jsch.ChannelSftp$RequestQueue.cancel(ChannelSftp.java:1246) 
        at com.jcraft.jsch.ChannelSftp$2.close(ChannelSftp.java:1503) 
        at org.apache.camel.util.IOHelper.close(IOHelper.java:326) 
        at org.apache.camel.component.file.FileOperations.writeFileByStream(FileOperations.java:404) 
        at org.apache.camel.component.file.FileOperations.storeFile(FileOperations.java:274) 
        at org.apache.camel.component.file.GenericFileProducer.writeFile(GenericFileProducer.java:277) 
        at org.apache.camel.component.file.GenericFileProducer.processExchange(GenericFileProducer.java:165) 
        at org.apache.camel.component.file.GenericFileProducer.process(GenericFileProducer.java:79) 
        at org.apache.camel.util.AsyncProcessorConverterHelper$ProcessorToAsyncProcessorBridge.process(AsyncProcessorConverterHelper.java:61) 
        at org.apache.camel.processor.SendProcessor.process(SendProcessor.java:129) 
        at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:77) 
        at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:448) 
        at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:191) 
        at org.apache.camel.processor.Pipeline.process(Pipeline.java:118) 
        at org.apache.camel.processor.Pipeline.process(Pipeline.java:80) 
        at org.apache.camel.processor.ChoiceProcessor.process(ChoiceProcessor.java:111) 
        at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:77) 
        at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:448) 
        at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:191) 
        at org.apache.camel.processor.Pipeline.process(Pipeline.java:118) 
        at org.apache.camel.processor.Pipeline.process(Pipeline.java:80) 
        at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:109) 
        at org.apache.camel.processor.Pipeline.process(Pipeline.java:60) 
        at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:166) 
        at org.apache.camel.component.file.GenericFileConsumer.processExchange(GenericFileConsumer.java:435) 
        at org.apache.camel.component.file.remote.RemoteFileConsumer.processExchange(RemoteFileConsumer.java:137) 
        at org.apache.camel.component.file.GenericFileConsumer.processBatch(GenericFileConsumer.java:211) 
        at org.apache.camel.component.file.GenericFileConsumer.poll(GenericFileConsumer.java:175) 
        at org.apache.camel.impl.ScheduledPollConsumer.doRun(ScheduledPollConsumer.java:174) 
        at org.apache.camel.impl.ScheduledPollConsumer.run(ScheduledPollConsumer.java:101) 
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471) 
        at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:304) 
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:178) 
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293) 
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) 
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) 
        at java.lang.Thread.run(Thread.java:744) 

After this error, this file and none of the remaining files are downloaded. I also tried using localWorkDirectory but saw that the file downloaded in the tmp directory also stuck at 98265 bytes.

+ Updates:

After further investigation it seems like there is a problem with JSCH library which Apache Camel internally uses. I get the below error after the wait time. I created a standalone code using JSCH for downloading which is also hanging in between the download. I also created a standalone code with another sftp api (not JSCH) which was able to download the files successfully.

WARN 04/11/15 07:49:58,877 org.slf4j.helpers.MarkerIgnoringBase :Error processing file RemoteFile[/User/User01/File02.csv] due to Cannot retrieve file: /User/User01/File02.csv. Caused by: [org.apache.camel.component.file.GenericFileOperationFailedException - Cannot retrieve file: /User/User01/File02.csv] 
org.apache.camel.component.file.GenericFileOperationFailedException: Cannot retrieve file: /User/User01/File02.csv 
    at org.apache.camel.component.file.remote.SftpOperations.retrieveFileToStreamInBody(SftpOperations.java:651) 
    at org.apache.camel.component.file.remote.SftpOperations.retrieveFile(SftpOperations.java:594) 
    at org.apache.camel.component.file.GenericFileConsumer.processExchange(GenericFileConsumer.java:396) 
    at org.apache.camel.component.file.remote.RemoteFileConsumer.processExchange(RemoteFileConsumer.java:137) 
    at org.apache.camel.component.file.GenericFileConsumer.processBatch(GenericFileConsumer.java:211) 
    at org.apache.camel.component.file.GenericFileConsumer.poll(GenericFileConsumer.java:175) 
    at org.apache.camel.impl.ScheduledPollConsumer.doRun(ScheduledPollConsumer.java:174) 
    at org.apache.camel.impl.ScheduledPollConsumer.run(ScheduledPollConsumer.java:101) 
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471) 
    at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:304) 
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:178) 
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293) 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) 
    at java.lang.Thread.run(Thread.java:744) 
Caused by: 4: 
    at com.jcraft.jsch.ChannelSftp.get(ChannelSftp.java:1513) 
    at com.jcraft.jsch.ChannelSftp.get(ChannelSftp.java:1266) 
    at org.apache.camel.component.file.remote.SftpOperations.retrieveFileToStreamInBody(SftpOperations.java:636) 
    ... 14 more 
Caused by: java.io.IOException: Pipe closed 
    at java.io.PipedInputStream.read(PipedInputStream.java:308) 
    at com.jcraft.jsch.Channel$MyPipedInputStream.updateReadSide(Channel.java:362) 
    at com.jcraft.jsch.ChannelSftp.get(ChannelSftp.java:1287) 
    ... 16 more 

Question 1: What might be going wrong? How can this issue be fixed?

Question 2: Is there a way to use any other library with Apache Camel for SFTP?

Any suggestions would be appreciated.

Thanks in advance.

Sumeet Kashyap
  • 143
  • 4
  • 15
  • Can you download the file from the same server to the same machine using the same account using a regular SFTP client? – Martin Prikryl Nov 19 '15 at 07:48
  • @MartinPrikryl I am unable to use a SFTP client like FileZilla/Tectia to download from this server as the access is restricted to command line from a particular IP only. But i did try downloading using sftp get and mget commands with which i am able to download all files successfully. – Sumeet Kashyap Nov 19 '15 at 08:40
  • What about the logs on the ftp server? Do they revel what is happening and why the pipe is being closed? Also try to play with the camel headers reconnectDelay and connectionTimeout. It could be that camel loses connection and times out. – Souciance Eqdam Rashti Nov 19 '15 at 11:42
  • @SoucianceEqdamRashti Updated question, the issue seems to be with JSCH library. The route is able to connect and download a few very small files but hangs afterwards so initial connection does not seem to be the issue. – Sumeet Kashyap Nov 21 '15 at 03:16

0 Answers0