1

我正在尝试使用骆驼通过 ftp 上传文件。我的代码如下

public static void main(String... args) throws Exception {
    CamelContext context = new DefaultCamelContext();

    context.addRoutes(new RouteBuilder() {
        @Override
        public void configure() {
             from("file:src/data?noop=true").to("ftp://myftp.com/ftp-test/?username=drauxxx&password=mypassword");
        }
    });
    context.start();
    Thread.sleep(10000);
    context.stop();
}

它连接良好,但是(正如您在日志中看到的那样)但是当我尝试存储时出现此错误:

[1) thread #1 - file://src/data] FileConsumer                   DEBUG Took 0.003 seconds to poll: src/data
[1) thread #1 - file://src/data] FileConsumer                   DEBUG Total 1 files to consume
[1) thread #1 - file://src/data] FileConsumer                   DEBUG About to process file: GenericFile[ReadMe.txt] using exchange: Exchange[ReadMe.txt]
[1) thread #1 - file://src/data] SendProcessor                  DEBUG >>>> Endpoint[ftp://drxxx.com/ftp-test/?password=******&username=drau9546] Exchange[ReadMe.txt]
[1) thread #1 - file://src/data] RemoteFileProducer             DEBUG Not already connected/logged in. Connecting to: Endpoint[ftp://drxxx.com/ftp-test/?password=******&username=drau9546]
[1) thread #1 - file://src/data] RemoteFileProducer             INFO  Connected and logged in to: Endpoint[ftp://drxxx.com/ftp-test/?password=******&username=drau9546]
[1) thread #1 - file://src/data] GenericFileConverter           DEBUG Read file src/data/ReadMe.txt (no charset)
[                          main] DefaultCamelContext            INFO  Apache Camel 2.10.0 (CamelContext: camel-1) is shutting down
[                          main] DefaultShutdownStrategy        INFO  Starting to graceful shutdown 1 routes (timeout 300 seconds)
[                          main] DefaultExecutorServiceManager  DEBUG Created new ThreadPool for source: org.apache.camel.impl.DefaultShutdownStrategy@77addb59 with name: ShutdownTask. -> org.apache.camel.util.concurrent.RejectableThreadPoolExecutor@bdccedd
[el-1) thread #2 - ShutdownTask] DefaultShutdownStrategy        DEBUG There are 1 routes to shutdown
[el-1) thread #2 - ShutdownTask] DefaultShutdownStrategy        DEBUG Route: route1 suspended and shutdown deferred, was consuming from: Endpoint[file://src/data?noop=true]
[el-1) thread #2 - ShutdownTask] DefaultShutdownStrategy        INFO  Waiting as there are still 2 inflight and pending exchanges to complete, timeout in 300 seconds.
[el-1) thread #2 - ShutdownTask] DefaultShutdownStrategy        INFO  Waiting as there are still 2 inflight and pending exchanges to complete, timeout in 299 seconds.
....

[1) thread #1 - file://src/data] RemoteFileProducer             WARN  Writing file failed with: Error writing file [ftp-test/ReadMe.txt]
[1) thread #1 - file://src/data] RemoteFileProducer             DEBUG Disconnecting from: Endpoint[ftp://drxxx.com/ftp-test/?password=******&username=drau9546]
[1) thread #1 - file://src/data] DefaultErrorHandler            DEBUG Failed delivery for (MessageId: ID-raccoonix-55914-1347631981229-0-1 on ExchangeId: ID-raccoonix-55914-1347631981229-0-2). On delivery attempt: 0 caught: org.apache.camel.component.file.GenericFileOperationFailedException: Error writing file [ftp-test/ReadMe.txt]
[1) thread #1 - file://src/data] GenericFileOnCompletion        DEBUG Done processing file: GenericFile[ReadMe.txt] using exchange: Exchange[ReadMe.txt]
[1) thread #1 - file://src/data] GenericFileOnCompletion        WARN  Rollback file strategy: org.apache.camel.component.file.strategy.GenericFileRenameProcessStrategy@2c31f2a7 for file: GenericFile[ReadMe.txt]
[1) thread #1 - file://src/data] FileUtil                       DEBUG Retrying attempt 0 to delete file: /home/andrea/workspace/transfer/src/data/ReadMe.txt.camelLock
[1) thread #1 - file://src/data] FileUtil                       DEBUG Tried 1 to delete file: /home/andrea/workspace/transfer/src/data/ReadMe.txt.camelLock with result: true
[1) thread #1 - file://src/data] DefaultErrorHandler            ERROR Failed delivery for (MessageId: ID-raccoonix-55914-1347631981229-0-1 on ExchangeId: ID-raccoonix-55914-1347631981229-0-2). Exhausted after delivery attempt: 1 caught: org.apache.camel.component.file.GenericFileOperationFailedException: Error writing file [ftp-test/ReadMe.txt]

是否有一些特定参数可用于正确的文件传输?是 ftp 服务器相关的问题吗?

4

1 回答 1

0

尝试

from("file:src/data?noop=true").to("ftp://drauxxx@myftp.com/ftp-test/?password=mypassword");

消除

context.stop();

因为它是一个实验代码,所以你不需要它。

还要检查您正在连接的 FTP 用户的用户权限。

于 2012-09-14T16:18:24.320 回答