camel ftp以递归方式导致ftp错误代码:226

时间:2016-03-19 14:48:29

标签: apache-camel ftp-client camel-ftp

我有一个非常简单的ftp路由,它应该递归地从URL下载文件。今天让它继续运行是非常重要的。

没有代理,没有额外的身份验证,没有防火墙。但是,它只下载第一个文件,然后套接字将被关闭。我已经尝试了不同的超时但他们没有解决问题。如果我不使用任何超时或额外的配置选项,或者如果我使用已注释掉的东西,则返回错误代码226,返回错误代码221。 226似乎不是一个错误,因为它只是表示服务器完成了传输。我在下面复制的堆栈跟踪。我会很感激你的回复,并提前感谢。

我在pollEnrich中使用的路由,因为我必须根据计时器启动它。

代码:

[...]
                        from("direct:ftp").routeId("ftp")
                                .log("### FTP is in progress ")
                                .pollEnrich().simple(ConfigData.getConfigData().getFtpUrl() 
                                        + "?binary=true&"
                                        + "recursive=true"
/*                                        + "soTimeout=300000&"
                                        + "stepwise=true&"
                                        + "ignoreFileNotFoundOrPermissionError=true&"
                                        + "ftpClient.dataTimeout=30000&"
                                        + "disconnect=true&"
                                        + "consumer.delay=1000" */
                                                    )
                                .to("file:modelFiles")
                                .end();

[...]

更新1

我删除了pollEnrich(),没有它就可以了。但是,我不能从另一条路线开始,例如从计时器。所以这是一个快速破解FTP运行。我也在这里复制代码,就像我使用幂等使​​用者一样,所以只下载那些尚未在磁盘上的文件。它对其他人也许有用。您可以在此处找到幂等消费者示例(Apache Camel ftp consumer loads the same files again and again)以获取更多信息。

Any further comments?

from(ConfigData.getConfigData().getFtpUrl() 
            + "?binary=true&"
            + "recursive=true&"
            + "passiveMode=true&"
            + "ftpClient.bufferSize=10000000&"
            + "localWorkDirectory=" + ConfigData.getConfigData().getLocalTmpDirectory())
    .idempotentConsumer(header("CamelFileName"), FileIdempotentRepository.fileIdempotentRepository(new File("data", "repo.dat")))
    .to("file:modelFiles")
    .log("Downloaded file ${file:name} complete.")
    .end(); 

堆栈跟踪

2016-03-19 15:27:53,921 [WARN|org.apache.camel.component.file.remote.FtpConsumer|MarkerIgnoringBase] Error processing file RemoteFile[2009-03-25/BioModels_Database-r13-sbml_files.tar.gz] due to File operation failed: null socket closed. Code: 221. Caused by: [org.apache.camel.component.file.GenericFileOperationFailedException - File operation failed: null socket closed. Code: 221]
org.apache.camel.component.file.GenericFileOperationFailedException: File **operation failed: null socket closed. Code: 221**
[...]
Caused by: java.net.SocketException: socket closed
        at java.net.SocketInputStream.socketRead0(Native Method)
        at java.net.SocketInputStream.read(Unknown Source)
        at java.net.SocketInputStream.read(Unknown Source)
        at sun.nio.cs.StreamDecoder.readBytes(Unknown Source)
        at sun.nio.cs.StreamDecoder.implRead(Unknown Source)
        at sun.nio.cs.StreamDecoder.read(Unknown Source)
        at java.io.InputStreamReader.read(Unknown Source)
        at java.io.BufferedReader.fill(Unknown Source)
        at java.io.BufferedReader.read(Unknown Source)
        at org.apache.commons.net.io.CRLFLineReader.readLine(CRLFLineReader.java:58)
        at org.apache.commons.net.ftp.FTP.__getReply(FTP.java:314)
        at org.apache.commons.net.ftp.FTP.__getReply(FTP.java:294)
        at org.apache.commons.net.ftp.FTP.sendCommand(FTP.java:483)
        at org.apache.commons.net.ftp.FTP.sendCommand(FTP.java:608)
        at org.apache.commons.net.ftp.FTP.cwd(FTP.java:828)
        at org.apache.commons.net.ftp.FTPClient.changeWorkingDirectory(FTPClient.java:1128)
        at org.apache.camel.component.file.remote.FtpOperations.doChangeDirectory(FtpOperations.java:769)

2016-03-19 12:42:16,068 [WARN|org.apache.camel.component.file.remote.FtpConsumer|MarkerIgnoringBase] Error processing file RemoteFile[2008-12-03/BioModels_Database-r12-sbml_files.tar.gz] due to File operation failed: null Socket Closed. Code: 226. Caused by: [org.apache.camel.component.file.GenericFileOperationFailedException - **File operation failed: null Socket Closed. Code: 226]**
[...]
Caused by: java.net.SocketException: Socket Closed
    at java.net.SocketInputStream.socketRead0(Native Method)
    at java.net.SocketInputStream.read(Unknown Source)
    at java.net.SocketInputStream.read(Unknown Source)
    at sun.nio.cs.StreamDecoder.readBytes(Unknown Source)
    at sun.nio.cs.StreamDecoder.implRead(Unknown Source)
    at sun.nio.cs.StreamDecoder.read(Unknown Source)
    at java.io.InputStreamReader.read(Unknown Source)
    at java.io.BufferedReader.fill(Unknown Source)
    at java.io.BufferedReader.read(Unknown Source)
    at org.apache.commons.net.io.CRLFLineReader.readLine(CRLFLineReader.java:58)
    at org.apache.commons.net.ftp.FTP.__getReply(FTP.java:314)
    at org.apache.commons.net.ftp.FTP.__getReply(FTP.java:294)
    at org.apache.commons.net.ftp.FTP.getReply(FTP.java:692)
    at org.apache.commons.net.ftp.FTPClient.completePendingCommand(FTPClient.java:1813)
    at org.apache.commons.net.ftp.FTPClient._retrieveFile(FTPClient.java:1885)
    at org.apache.commons.net.ftp.FTPClient.retrieveFile(FTPClient.java:1845)
    at org.apache.camel.component.file.remote.FtpOperations.retrieveFileToStreamInBody(FtpOperations.java:367)

解决方案:

如在Upadete 1中添加的那样,我不使用pollEnrich()。现在无法从计时器启动路径,但它可以正常工作。所以我将结束这个问题。我非常喜欢幂等消费者的想法(与原始问题无关)。

2 个答案:

答案 0 :(得分:0)

不要忘记pollEnrich删除oldExchange并保留newExchange。

所以你不想做一个from(“ftp”)。pollEnrich(“timer”)但是来自(“timer”)。pollEnrich(“ftp”)。

答案 1 :(得分:0)

请参阅问题末尾的解决方案