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

camel ftp in recursive manner results in ftp error code: 226

我有一个非常简单的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()。该路线现在无法从计时器开始,但它可以工作。所以我会关闭这个问题。我真的很喜欢幂等消费者的想法(与原始问题无关)。

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

所以你不想做一个 from("ftp").pollEnrich("timer") 而是一个 from("timer").pollEnrich("ftp") .

参见问题末尾的解决方案