Search code examples
javaapache-camelsftpcamel-ftp

Can't create new local work file during consume a file from SFTP


I'm using camel version 2.15.2

I've an endpoint

final String endpoint = "sftp://myUsername@$myHost:22/test-dir/?connectTimeout=5000&password=MySuperSecretPassword&ignoreFileNotFoundOrPermissionError=false&fileName=FABT_Index_DE.xls&delete=false&localWorkDirectory=/test-dir/

and i do the following to fetch the named file from the SFTP

  @Autowired
  private CamelContext camelContext;

  ...some Stuff...

  private Exchange fetchFile(final String enpoint, final long timeout) {
        final ConsumerTemplate consumer = camelContext.createConsumerTemplate();
        return consumer.receive(endpoint, timeout);
  }

When i start my application on my pc (OS = windows) ... all is fine. The file get fetched from the SFTP. I thought it would be a good idea to test, if the application runs on an other machine... so i copied my jar to the SFTP (OS = linux) and run it there... (it's the same machine where the file is placed)

Now i get the following exception:

2015-07-16 15:27:37,117 [Camel (camel-1) thread #0 - sftp://myUsername@myHost:22/test-dir/] TRACE o.a.c.c.file.remote.SftpConsumer: postPollCheck on sftp://myUsername@myHost:22
2015-07-16 15:27:37,117 [Camel (camel-1) thread #0 - sftp://myUsername@myHost:22/test-dir/] TRACE o.a.camel.impl.ScheduledPollConsumer: Polled 1 messages
2015-07-16 15:27:37,117 [Camel (camel-1) thread #0 - sftp://myUsername@myHost:22/test-dir/] TRACE o.a.camel.impl.ScheduledPollConsumer: Finished polling: Endpoint[sftp://myUsername@myHost:22/test-dir/?connectTimeout=5000&delete=false&fileName=FABT_Index_DE.xls&ignoreFileNotFoundOrPermissionError=false&localWorkDirectory=%2Ftest-dir%2F&password=xxxxxx]
2015-07-16 15:27:37,118 [Camel (camel-1) thread #0 - sftp://myUsername@myHost:22/test-dir/] TRACE o.a.camel.impl.ScheduledPollConsumer: doRun() done with idleCounter=0, errorCounter=0
2015-07-16 15:27:37,118 [Camel (camel-1) thread #0 - sftp://myUsername@myHost:22/test-dir/] TRACE o.a.camel.impl.ScheduledPollConsumer: Scheduled task completed on: Endpoint[sftp://myUsername@myHost:22/test-dir/?connectTimeout=5000&delete=false&fileName=FABT_Index_DE.xls&ignoreFileNotFoundOrPermissionError=false&localWorkDirectory=%2Ftest-dir%2F&password=xxxxxx]
2015-07-16 15:27:37,619 [Camel (camel-1) thread #0 - sftp://myUsername@myHost:22/test-dir/] TRACE o.a.camel.impl.ScheduledPollConsumer: Scheduled task started on:   Endpoint[sftp://myUsername@myHost:22/test-dir/?connectTimeout=5000&delete=false&fileName=FABT_Index_DE.xls&ignoreFileNotFoundOrPermissionError=false&localWorkDirectory=%2Ftest-dir%2F&password=xxxxxx]
2015-07-16 15:27:37,620 [Camel (camel-1) thread #0 - sftp://myUsername@myHost:22/test-dir/] TRACE o.a.camel.impl.ScheduledPollConsumer: Starting to poll: Endpoint[sftp://myUsername@myHost:22/test-dir/?connectTimeout=5000&delete=false&fileName=FABT_Index_DE.xls&ignoreFileNotFoundOrPermissionError=false&localWorkDirectory=%2Ftest-dir%2F&password=xxxxxx]
2015-07-16 15:27:37,620 [Camel (camel-1) thread #0 - sftp://myUsername@myHost:22/test-dir/] TRACE o.a.c.c.file.remote.SftpConsumer: prePollCheck on sftp://myUsername@myHost:22
2015-07-16 15:27:37,621 [Camel (camel-1) thread #0 - sftp://myUsername@myHost:22/test-dir/] TRACE o.a.c.c.file.remote.SftpOperations: getCurrentDirectory()
2015-07-16 15:27:37,621 [Camel (camel-1) thread #0 - sftp://myUsername@myHost:22/test-dir/] TRACE o.a.c.c.file.remote.SftpOperations: Current dir: /vol2/home/myUsername
2015-07-16 15:27:37,621 [Camel (camel-1) thread #0 - sftp://myUsername@myHost:22/test-dir/] TRACE o.a.c.c.file.remote.SftpConsumer: doPollDirectory from absolutePath: test-dir, dirName: null
2015-07-16 15:27:37,621 [Camel (camel-1) thread #0 - sftp://myUsername@myHost:22/test-dir/] TRACE o.a.c.c.file.remote.SftpOperations: changeCurrentDirectory(test-dir)
2015-07-16 15:27:37,621 [Camel (camel-1) thread #0 - sftp://myUsername@myHost:22/test-dir/] TRACE o.a.c.c.file.remote.SftpOperations: Compacted path: test-dir -> test-dir using separator: /
2015-07-16 15:27:37,621 [Camel (camel-1) thread #0 - sftp://myUsername@myHost:22/test-dir/] TRACE o.a.c.c.file.remote.SftpOperations: getCurrentDirectory()
2015-07-16 15:27:37,621 [Camel (camel-1) thread #0 - sftp://myUsername@myHost:22/test-dir/] TRACE o.a.c.c.file.remote.SftpOperations: Current dir: /vol2/home/myUsername
2015-07-16 15:27:37,621 [Camel (camel-1) thread #0 - sftp://myUsername@myHost:22/test-dir/] TRACE o.a.c.c.file.remote.SftpOperations: Changing directory: test-dir
2015-07-16 15:27:37,622 [Camel (camel-1) thread #0 - sftp://myUsername@myHost:22/test-dir/] TRACE o.a.c.c.file.remote.SftpConsumer: Polling directory: test-dir
2015-07-16 15:27:37,622 [Camel (camel-1) thread #0 - sftp://myUsername@myHost:22/test-dir/] TRACE o.a.c.c.file.remote.SftpOperations: listFiles(.)
2015-07-16 15:27:37,624 [Camel (camel-1) thread #0 - sftp://myUsername@myHost:22/test-dir/] TRACE o.a.c.c.file.remote.SftpConsumer: Found 9 in directory: test-dir
2015-07-16 15:27:37,625 [Camel (camel-1) thread #0 - sftp://myUsername@myHost:22/test-dir/] TRACE o.a.c.c.file.remote.SftpConsumer: SftpFile[fileName=FASM_Index_DE.xls, longName=-rw-r--r--    1 myUsername  users       81920 Jun 30 16:46 FASM_Index_DE.xls, dir=false]
2015-07-16 15:27:37,625 [Camel (camel-1) thread #0 - sftp://myUsername@myHost:22/test-dir/] TRACE o.a.c.i.c.DefaultTypeConverter: Converting java.lang.String -> java.lang.String with value: FABT_Index_DE.xls
2015-07-16 15:27:37,625 [Camel (camel-1) thread #0 - sftp://myUsername@myHost:22/test-dir/] TRACE o.a.c.c.file.remote.SftpConsumer: File did not match. Will skip this file: RemoteFile[FASM_Index_DE.xls]
2015-07-16 15:27:37,625 [Camel (camel-1) thread #0 - sftp://myUsername@myHost:22/test-dir/] TRACE o.a.c.c.file.remote.SftpConsumer: SftpFile[fileName=.., longName=drwxr-xr-x    8 myUsername  users        4096 Jul 16 15:27 .., dir=true]
2015-07-16 15:27:37,625 [Camel (camel-1) thread #0 - sftp://myUsername@myHost:22/test-dir/] TRACE o.a.c.c.file.remote.SftpConsumer: SftpFile[fileName=., longName=drwxr-xr-x    2 myUsername  users        4096 Jul 16 15:24 ., dir=true]
2015-07-16 15:27:37,625 [Camel (camel-1) thread #0 - sftp://myUsername@myHost:22/test-dir/] TRACE o.a.c.c.file.remote.SftpConsumer: SftpFile[fileName=FABT_Index_DE.xls, longName=-rw-r--r--    1 myUsername  users      129024 Jun 30 16:46 FABT_Index_DE.xls, dir=false]
2015-07-16 15:27:37,625 [Camel (camel-1) thread #0 - sftp://myUsername@myHost:22/test-dir/] TRACE o.a.c.c.file.remote.SftpConsumer: SftpFile[fileName=test.txt, longName=-rw-r--r--    1 myUsername  users          18 Jul 16 15:24 test.txt, dir=false]
2015-07-16 15:27:37,625 [Camel (camel-1) thread #0 - sftp://myUsername@myHost:22/test-dir/] TRACE o.a.c.c.file.remote.SftpConsumer: File did not match. Will skip this file: RemoteFile[test.txt]
2015-07-16 15:27:37,626 [Camel (camel-1) thread #0 - sftp://myUsername@myHost:22/test-dir/] TRACE o.a.c.c.file.remote.SftpConsumer: SftpFile[fileName=FAWH_Index_DE.xls, longName=-rw-r--r--    1 myUsername  users      180224 Jun 30 16:46 FAWH_Index_DE.xls, dir=false]
2015-07-16 15:27:37,626 [Camel (camel-1) thread #0 - sftp://myUsername@myHost:22/test-dir/] TRACE o.a.c.c.file.remote.SftpConsumer: File did not match. Will skip this file: RemoteFile[FAWH_Index_DE.xls]
2015-07-16 15:27:37,626 [Camel (camel-1) thread #0 - sftp://myUsername@myHost:22/test-dir/] TRACE o.a.c.c.file.remote.SftpConsumer: SftpFile[fileName=FAPG_Index_DE.xls, longName=-rw-r--r--    1 myUsername  users      101888 Jun 30 16:46 FAPG_Index_DE.xls, dir=false]
2015-07-16 15:27:37,626 [Camel (camel-1) thread #0 - sftp://myUsername@myHost:22/test-dir/] TRACE o.a.c.c.file.remote.SftpConsumer: File did not match. Will skip this file: RemoteFile[FAPG_Index_DE.xls]
2015-07-16 15:27:37,626 [Camel (camel-1) thread #0 - sftp://myUsername@myHost:22/test-dir/] TRACE o.a.c.c.file.remote.SftpConsumer: SftpFile[fileName=FAPP_Index_DE.xls, longName=-rw-r--r--    1 myUsername  users       78336 Jun 30 16:46 FAPP_Index_DE.xls, dir=false]
2015-07-16 15:27:37,626 [Camel (camel-1) thread #0 - sftp://myUsername@myHost:22/test-dir/] TRACE o.a.c.c.file.remote.SftpConsumer: File did not match. Will skip this file: RemoteFile[FAPP_Index_DE.xls]
2015-07-16 15:27:37,626 [Camel (camel-1) thread #0 - sftp://myUsername@myHost:22/test-dir/] TRACE o.a.c.c.file.remote.SftpConsumer: SftpFile[fileName=FAHG_Index_DE.xls, longName=-rw-r--r--    1 myUsername  users      149504 Jun 30 16:46 FAHG_Index_DE.xls, dir=false]
2015-07-16 15:27:37,626 [Camel (camel-1) thread #0 - sftp://myUsername@myHost:22/test-dir/] TRACE o.a.c.c.file.remote.SftpConsumer: File did not match. Will skip this file: RemoteFile[FAHG_Index_DE.xls]
2015-07-16 15:27:37,626 [Camel (camel-1) thread #0 - sftp://myUsername@myHost:22/test-dir/] TRACE o.a.c.c.file.remote.SftpOperations: changeCurrentDirectory(/vol2/home/myUsername)
2015-07-16 15:27:37,627 [Camel (camel-1) thread #0 - sftp://myUsername@myHost:22/test-dir/] TRACE o.a.c.c.file.remote.SftpOperations: Compacted path: /vol2/home/myUsername -> /vol2/home/myUsername using separator: /
2015-07-16 15:27:37,627 [Camel (camel-1) thread #0 - sftp://myUsername@myHost:22/test-dir/] TRACE o.a.c.c.file.remote.SftpOperations: getCurrentDirectory()
2015-07-16 15:27:37,627 [Camel (camel-1) thread #0 - sftp://myUsername@myHost:22/test-dir/] TRACE o.a.c.c.file.remote.SftpOperations: Current dir: /vol2/home/myUsername/test-dir
2015-07-16 15:27:37,627 [Camel (camel-1) thread #0 - sftp://myUsername@myHost:22/test-dir/] TRACE o.a.c.c.file.remote.SftpOperations: getCurrentDirectory()
2015-07-16 15:27:37,627 [Camel (camel-1) thread #0 - sftp://myUsername@myHost:22/test-dir/] TRACE o.a.c.c.file.remote.SftpOperations: Current dir: /vol2/home/myUsername/test-dir
2015-07-16 15:27:37,627 [Camel (camel-1) thread #0 - sftp://myUsername@myHost:22/test-dir/] TRACE o.a.c.c.file.remote.SftpOperations: Changing directory: ..
2015-07-16 15:27:37,628 [Camel (camel-1) thread #0 - sftp://myUsername@myHost:22/test-dir/] DEBUG o.a.c.c.file.remote.SftpConsumer: Took 0.007 seconds to poll: test-dir/
2015-07-16 15:27:37,628 [Camel (camel-1) thread #0 - sftp://myUsername@myHost:22/test-dir/] DEBUG o.a.c.c.file.remote.SftpConsumer: Total 1 files to consume
2015-07-16 15:27:37,628 [Camel (camel-1) thread #0 - sftp://myUsername@myHost:22/test-dir/] TRACE o.a.c.c.file.remote.SftpConsumer: Processing file: RemoteFile[FABT_Index_DE.xls]
2015-07-16 15:27:37,628 [Camel (camel-1) thread #0 - sftp://myUsername@myHost:22/test-dir/] TRACE o.a.c.c.file.remote.SftpConsumer: Retrieving file: test-dir/FABT_Index_DE.xls from: Endpoint[sftp://myUsername@myHost:22/test-dir/?connectTimeout=5000&delete=false&fileName=FABT_Index_DE.xls&ignoreFileNotFoundOrPermissionError=false&localWorkDirectory=%2Ftest-dir%2F&password=xxxxxx]
2015-07-16 15:27:37,629 [Camel (camel-1) thread #0 - sftp://myUsername@myHost:22/test-dir/] TRACE o.a.c.c.file.remote.SftpOperations: retrieveFile(test-dir/FABT_Index_DE.xls)
2015-07-16 15:27:37,630 [Camel (camel-1) thread #0 - sftp://myUsername@myHost:22/test-dir/] WARN  o.a.c.c.file.remote.SftpConsumer: Error processing file RemoteFile[FABT_Index_DE.xls] due to Cannot create new local work file: /test-dir/FABT_Index_DE.xls.
Caused by:  [org.apache.camel.component.file.GenericFileOperationFailedException - Cannot create new local work file: /test-dir/FABT_Index_DE.xls]
org.apache.camel.component.file.GenericFileOperationFailedException: Cannot create new local work file: /test-dir/FABT_Index_DE.xls
    at org.apache.camel.component.file.remote.SftpOperations.retrieveFileToFileInLocalWorkDirectory(SftpOperations.java:702) ~[aii.jar:na]
    at org.apache.camel.component.file.remote.SftpOperations.retrieveFile(SftpOperations.java:591) ~[aii.jar:na]
    at org.apache.camel.component.file.GenericFileConsumer.processExchange(GenericFileConsumer.java:396) [aii.jar:na]
    at org.apache.camel.component.file.remote.RemoteFileConsumer.processExchange(RemoteFileConsumer.java:137) [aii.jar:na]
    at org.apache.camel.component.file.GenericFileConsumer.processBatch(GenericFileConsumer.java:211) [aii.jar:na]
    at org.apache.camel.component.file.GenericFileConsumer.poll(GenericFileConsumer.java:175) [aii.jar:na]
    at org.apache.camel.impl.ScheduledPollConsumer.doRun(ScheduledPollConsumer.java:174) [aii.jar:na]
    at org.apache.camel.impl.ScheduledPollConsumer.run(ScheduledPollConsumer.java:101) [aii.jar:na]
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471) [na:1.7.0_45]
    at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:304) [na:1.7.0_45]
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:178) [na:1.7.0_45]
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293) [na:1.7.0_45]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [na:1.7.0_45]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [na:1.7.0_45]
    at java.lang.Thread.run(Thread.java:744) [na:1.7.0_45]

Can anyone tell me why i get this exception - instead of fetching the file from SFTP?


Solution

  • i've found out the following:

    i used for the endpoint and the local-working-directory the same String test-dir. After some experiments it seems that for the endpoint definition

    • final String endpoint = "sftp://myUsername@$myHost:22/test-dir/?connect ...

    the test-dir is a relative path. e.g. This directory is located at /vol/usr/home/MyTestUser/test-dir and /vol/usr/home/myUsername/ is the home-directory of the SFTP-User (or the directory you get when you logged in via ssh) - it's ok to define the endpoint with /test-dir/

    But for the option localWorkDirectory

    • final String endpoint = " ... &localWorkDirectory=/test-dir/ ..."

    it seems the test-dir is an absolute path. Because i try to run the application on the SFTP i got no permission to write to the absolute directory /test-dir/ so i changed this directory to /vol/usr/home/myUsername/MyTempDirectory/ and add the option &stepwise=false. And now it workes. The endpoint is now:

    final String endpoint = "sftp://myUsername@myHost:22/test-dir/connectTimeout=5000&password=MySuperSecretPassword&ignoreFileNotFoundOrPermissionError=false&fileName=FABT_Index_DE.xls&delete=false&localWorkDirectory=/vol/usr/home/myUsername/MyTempDirectory/&stepwise=false";
    

    Perhaps someone can clarify it more precise...