Hi Claus, thanks I will give it a try. One more quick question. I
tried to take the route out of it entirely, and just force it via
this:
try {
Endpoint ftp = context.getEndpoint(url);
PollingConsumer consumer = ftp.createPollingConsumer();
consumer.start();
Exchange result = consumer.receive();
consumer.stop();
} catch (Exception e) {
This produces:
12:19:48,319 DEBUG [Thread: 1 RemoteFileComponent]
impl.ScheduledPollConsumer (ScheduledPollConsumer.java:63) - Starting
to poll: Endpoint[sftp://[email protected]/home/toor/newfile.txt]
12:19:48,319 DEBUG [Thread: 1 RemoteFileComponent] remote.SftpConsumer
(SftpConsumer.java:94) - Polling
sftp://[email protected]:22/home/toor/newfile.txt
12:19:48,319 DEBUG [Thread: 1 RemoteFileComponent] remote.SftpConsumer
(SftpConsumer.java:71) - Session isn't connected, trying to recreate
and connect.
12:19:49,881 DEBUG [Thread: 1 RemoteFileComponent] remote.SftpConsumer
(SftpConsumer.java:75) - Channel isn't connected, trying to recreate
and connect.
12:19:50,053 INFO [Thread: 1 RemoteFileComponent] remote.SftpConsumer
(SftpConsumer.java:78) - Connected to sftp://[email protected]:22
12:19:50,069 WARN [Thread: 1 RemoteFileComponent] remote.SftpConsumer
(SftpConsumer.java:122) - Exception occured during polling:
com.jcraft.jsch.SftpException message: No such file
12:19:50,069 DEBUG [Thread: 1 RemoteFileComponent] remote.SftpConsumer
(SftpConsumer.java:83) - Disconnecting from
sftp://[email protected]:22
12:19:50,084 WARN [Thread: 1 RemoteFileComponent]
impl.ScheduledPollConsumer (ScheduledPollConsumer.java:68) - An
exception occured while polling:
Endpoint[sftp://[email protected]/home/toor/newfile.txt]: No such
file
2: No such file
Is there something wrong with the remote endpoint path? The file does
indeed exist. I can use http://winscp.net/eng/index.php to login via
SFTP and download the file.
On the remote host ->
t...@xubuntu-oracle11g:~$ pwd
/home/toor
t...@xubuntu-oracle11g:~$ ls -al | grep newfile.txt
-rw-r--r-- 1 toor toor 18 2009-01-09 11:46 newfile.txt
On Fri, Jan 9, 2009 at 12:27 PM, Claus Ibsen <[email protected]> wrote:
> Hi
>
> Dynamically adding routes is not support (yet). So the addRouteBuilder
> stuff is not quite possible.
>
> So instead have a route like this
>
> from(seda queue).process(your processor code below).to(file)
>
> And then in your processor you can set the target filename the file
> should be saved in your local filesystem by adding a header to IN
> message
> org.apache.camel.file.name
> There is also a constant for it at FileComponent
>
> Note: The file endpoint can be configured with a root path that the
> filename should be stored relative to, such as
> "file://mycoolapp/inbox/"
>
>
>
> On Fri, Jan 9, 2009 at 6:15 PM, Davis Ford <[email protected]> wrote:
>> Hi, I'm trying to do something fairly simple: copy a file via sftp to
>> localhost. I build a route with sftp and file components. This is
>> event driven, so I don't want to have a consumer constantly polling.
>>
>> I'm trying to follow the sample described at "Consuming a remote FTP
>> server triggered by a route" http://activemq.apache.org/camel/ftp.html
>> where it shows a message comes in from a seda queue that has the
>> path/host to the file.
>>
>> I'm trying to do exactly the same thing without the seda queue.
>>
>> See the method below which will be executed when I receive an event
>> that a file is ready to be downloaded. context is CamelContext
>> injected via spring so it should already be started.
>>
>> @Override
>> public File download(String host, String localDirectory, String
>> remotePath) {
>> // the sftp url
>> final String url = getUrl(host, remotePath);
>> // path to local file
>> final String localFile = getLocalFilePath(localDirectory,
>> remotePath);
>> try {
>> context.addRoutes(new RouteBuilder() {
>> public void configure() {
>> from(url).process(new Processor() {
>> @Override
>> public void process(Exchange
>> exchange) throws Exception {
>> Endpoint ftp =
>> context.getEndpoint(url);
>> PollingConsumer
>> consumer = ftp.createPollingConsumer();
>> consumer.start();
>> Exchange result =
>> consumer.receive();
>>
>> exchange.getIn().setBody(result.getIn().getBody());
>> consumer.stop();
>> }
>> }).to("file://"+localFile);
>> }
>> });
>> } catch (Exception e) {
>> // TODO Auto-generated catch block
>> e.printStackTrace();
>> }
>> return null;
>> }
>>
>> When I try this, the log messages indicate:
>>
>> remote endpoint is created ->
>>
>> 12:02:28,538 DEBUG [main] impl.DefaultCamelContext
>> (DefaultCamelContext.java:333) -
>> sftp://[email protected]/home/toor/newfile.txt?password=password&binary=true&directory=false&consumer.delay=5000&consumer.deleteFile=true
>> converted to endpoint:
>> Endpoint[sftp://[email protected]/home/toor/newfile.txt] by
>> component: RemoteFileComponent
>>
>> local file endpoint is created ->
>>
>> 12:02:28,647 DEBUG [main] impl.DefaultComponentResolver
>> (DefaultComponentResolver.java:67) - Found component: file via type:
>> org.apache.camel.component.file.FileComponent via
>> META-INF/services/org/apache/camel/component/file
>> 12:02:28,663 DEBUG [main] impl.DefaultComponent
>> (DefaultComponent.java:79) - Creating endpoint
>> uri=[file://C:\SVN\.\target\newfile.txt],
>> path=[C:\SVN\.\target\newfile.txt], parameters=[{}]
>> 12:02:28,663 DEBUG [main] impl.DefaultCamelContext
>> (DefaultCamelContext.java:333) - file://C:\SVN\.\target\newfile.txt
>> converted to endpoint: Endpoint[file://C:\SVN\.\target\newfile.txt] by
>> component: org.apache.camel.component.file.filecompon...@9b87f6
>>
>> consumer is started ->
>>
>> 12:02:28,803 INFO [main] remote.SftpConsumer (SftpConsumer.java:51) -
>> Starting
>> 12:02:28,819 DEBUG [main] impl.DefaultCamelContext
>> (DefaultCamelContext.java:401) - Adding routes from: Routes:
>> [Route[[From[sftp://[email protected]/home/toor/newfile.txt]] ->
>> [Interceptor[Delegate(Pipeline[DeadLetterChannel[Delegate(sftpfiledownloader$...@8b6c39),
>> RecipientList[log:org.apache.camel.DeadLetterChannel?level=error]],
>> DeadLetterChannel[Delegate(sendTo(Endpoint[file://C:\SVN\.\target\newfile.txt])),
>> RecipientList[log:org.apache.camel.DeadLetterChannel?level=error]]])]]]]
>> routes: []
>>
>> ...but nothing happens after that? the file isn't copied, no
>> exception is thrown, etc. I call it from a JUnit test, and the test
>> just exits. I think I must be missing something simple?
>>
>> Regards,
>> Davis
>>
>
>
>
> --
>
> /Claus Ibsen
> Apache Camel Committer
> Blog: http://davsclaus.blogspot.com/
>
--
Zeno Consulting, Inc.
http://www.zenoconsulting.biz
248.894.4922 phone
313.884.2977 fax