0

我正在尝试使用相当简单的路由通过 SFTP 将文件从远程服务器下载到本地目录。

我面临的问题是该路由能够下载小文件(200 字节),但对于较大的文件(200 KB),它恰好卡在 98265 字节。大约 30 秒后,我收到管道关闭错误。

我正在使用 Apache Camel 版本:2.15.3

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

收件人: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) 

出现此错误后,不会下载此文件和其余文件。我也尝试使用 localWorkDirectory 但看到下载到 tmp 目录中的文件也停留在 98265 字节。

+ 更新:

经过进一步调查,Apache Camel 内部使用的 JSCH 库似乎存在问题。等待时间后出现以下错误。我使用 JSCH 创建了一个用于下载的独立代码,该代码也挂在下载之间。我还使用另一个能够成功下载文件的 sftp api(不是 JSCH)创建了一个独立代码。

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 

问题1:可能出了什么问题?如何解决这个问题?

问题 2:有没有办法将任何其他库与 Apache Camel 一起用于 SFTP?

任何建议,将不胜感激。

提前致谢。

4

0 回答 0