You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by deepak_a <an...@gmail.com> on 2013/07/24 12:52:57 UTC

SFTP Support to run GET PUT commands

All,

I am currently using Apace Camel for connecting to various end points -
webservice, JMS, file etc.
Now I have a requirement to PUT/GET files from an external system using
SFTP.

Is there support in Camel to run GET & PUT commands?

e.g.
put {local_file_name}  //<Directory>
get //<directory> c:/myFile

In addition I may need to use the following commands

* CD
* LS

If it does support - would appreciate if someone can point to an example on
how this in configured?
I checked http://camel.apache.org/ftp.html but was not able to see if its
possible to execute these commands.

regards
D



--
View this message in context: http://camel.465427.n5.nabble.com/SFTP-Support-to-run-GET-PUT-commands-tp5736198.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: SFTP Support to run GET PUT commands

Posted by deepak_a <an...@gmail.com>.
On further analysis - it appears the sFTP server is expecting ONLY the
following sequence of operations to GET a file



(1) Change to DTCC-assigned directory 		cd //artdialu.d3346
(2) List contents of directory   			ls //artdialu.d3346 
(3) Set transfer mode & file characteristics		ls
/+recfm=fb,mode=text,lrecl=300
(4) GET input SYSID (file) to directory		get
//artdialu.d3346.p0298.p0211.d120311.c01 c:/myfile

i guess steps 2 and 3 are optional - but I need to traverse to a specific
directory and only then access a file from it.

is this something achievable?

I have tried the below route (I can confirm that directory DTS4.UP.G2TLR is
present with some files in it)

		<route>
			<from
uri="sftp://F7DGTLRW@207.45.41.162:22//DTS4.UP.G2TLR?password=lomb456&amp;noop=true&amp;binary=true&amp;delay=60000&amp;stepwise=false"/>
			<to uri="file:/opt/share/SFTP_OUT"/>
		</route>


I can see that the route tries to extract the file but see the subsequent
exception (this repeats for all the available files in that directory)

[2013-08-12 15:52:41,393 Camel (camel) thread #2 -
sftp://F7DGTLRW@207.45.41.162:22///DTS4.UP.G2TLR] SftpConsumer                  
ERROR Caused by:
[org.apache.camel.component.file.GenericFileOperationFailedException -
Cannot retrieve file: /DTS4.UP.G2TLR/BOOK1.CSV.D0713.T2213966]
org.apache.camel.component.file.GenericFileOperationFailedException: Cannot
retrieve file: /DTS4.UP.G2TLR/BOOK1.CSV.D0713.T2213966
	at
org.apache.camel.component.file.remote.SftpOperations.retrieveFileToStreamInBody(SftpOperations.java:516)[camel-ftp-2.9.0.jar:2.9.0] 



--
View this message in context: http://camel.465427.n5.nabble.com/SFTP-Support-to-execute-GET-PUT-commands-tp5736198p5737163.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: SFTP Support to run GET PUT commands

Posted by deepak_a <an...@gmail.com>.
Thanks,

I am getting an exception when I try to GET a file from SFTP.
My route is set up as follows

		<route>
			<from
uri="sftp://XXXXXXXX@XXX.XX.XX.XXX:22///XXXX.XX.XXXXX?password=XXXXXXX&amp;noop=true&amp;binary=true&amp;delay=60000&amp;stepwise=false"/>
			<to uri="file:/opt/share/SFTP_OUT"/>
		</route>

The exception is

[2013-08-12 14:46:04,751 Camel (camel) thread #2 -
sftp://XXXXXXXX@XXX.XX.XX.XXX:22///XXXX.XX.XXXXX] SftpConsumer                  
ERROR Caused by:
[org.apache.camel.component.file.GenericFileOperationFailedException -
Cannot retrieve file: /DTS4.UP.G2TLR/BOOK1.CSV.D0806.T4748300]
org.apache.camel.component.file.GenericFileOperationFailedException: Cannot
retrieve file: /DTS4.UP.G2TLR/BOOK1.CSV.D0806.T4748300
	at
org.apache.camel.component.file.remote.SftpOperations.retrieveFileToStreamInBody(SftpOperations.java:516)[camel-ftp-2.9.0.jar:2.9.0]
	at
org.apache.camel.component.file.remote.SftpOperations.retrieveFile(SftpOperations.java:473)[camel-ftp-2.9.0.jar:2.9.0]
	at
org.apache.camel.component.file.GenericFileConsumer.processExchange(GenericFileConsumer.java:333)[camel-core-2.9.0.jar:2.9.0]
	at
org.apache.camel.component.file.remote.RemoteFileConsumer.processExchange(RemoteFileConsumer.java:94)[camel-ftp-2.9.0.jar:2.9.0]
	at
org.apache.camel.component.file.GenericFileConsumer.processBatch(GenericFileConsumer.java:175)[camel-core-2.9.0.jar:2.9.0]
	at
org.apache.camel.component.file.GenericFileConsumer.poll(GenericFileConsumer.java:136)[camel-core-2.9.0.jar:2.9.0]
	at
org.apache.camel.impl.ScheduledPollConsumer.doRun(ScheduledPollConsumer.java:140)[camel-core-2.9.0.jar:2.9.0]
	at
org.apache.camel.impl.ScheduledPollConsumer.run(ScheduledPollConsumer.java:92)[camel-core-2.9.0.jar:2.9.0]
	at java.util.concurrent.Executors$RunnableAdapter.call(Unknown
Source)[:1.6.0_38]
	at java.util.concurrent.FutureTask$Sync.innerRunAndReset(Unknown
Source)[:1.6.0_38]
	at java.util.concurrent.FutureTask.runAndReset(Unknown Source)[:1.6.0_38]
	at
java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$101(Unknown
Source)[:1.6.0_38]
	at
java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.runPeriodic(Unknown
Source)[:1.6.0_38]
	at
java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(Unknown
Source)[:1.6.0_38]
	at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown
Source)[:1.6.0_38]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown
Source)[:1.6.0_38]
	at java.lang.Thread.run(Unknown Source)[:1.6.0_38]


Its definitively not an authentication issue, since I can see that I am able
to connect successfully (as shown in below logs)


[2013-08-12 14:46:02,661 Camel (camel) thread #2 -
sftp://F7DGTLRW@207.45.41.162:22///DTS4.UP.G2TLR] SftpOperations                
INFO  JSCH -> Next authentication method: password
[2013-08-12 14:46:02,737 Camel (camel) thread #2 -
sftp://F7DGTLRW@207.45.41.162:22///DTS4.UP.G2TLR] SftpOperations                
INFO  JSCH -> Authentication succeeded (password).
[2013-08-12 14:46:02,763 LockManager] DbLockManager                  INFO 
Table Lock result:true
[2013-08-12 14:46:03,655 Camel (camel) thread #2 -
sftp://F7DGTLRW@207.45.41.162:22///DTS4.UP.G2TLR] SftpOperations                
INFO  Connected to sftp://F7DGTLRW@207.45.41.162:22
[2013-08-12 14:46:03,655 Camel (camel) thread #2 -
sftp://F7DGTLRW@207.45.41.162:22///DTS4.UP.G2TLR] SftpConsumer                  
INFO  Connected and logged in to: sftp://F7DGTLRW@207.45.41.162:22
[2013-08-12 14:46:03,766 LockManager] DbLockManager                  INFO 
Table Lock result:true


----------------


If I try to connect to SFTP site, i can see the following

sftp> CD //DTS4.UP.G2TLR
sftp> LS //DTS4.UP.G2TLR
//DTS4.UP.G2TLR/BOOK1.CSV.D0713.T0903622      
//DTS4.UP.G2TLR/BOOK1.CSV.D0713.T2200378      
//DTS4.UP.G2TLR/BOOK1.CSV.D0713.T2208865      
//DTS4.UP.G2TLR/BOOK1.CSV.D0713.T2213966      
//DTS4.UP.G2TLR/BOOK1.CSV.D0806.T4633586       
//DTS4.UP.G2TLR/BOOK1.CSV.D0806.T4748300      
//DTS4.UP.G2TLR/S40750.D0713.T0644847 


=> Just to confirm that the files do exist in the FTP Site.


regards
D






--
View this message in context: http://camel.465427.n5.nabble.com/SFTP-Support-to-execute-GET-PUT-commands-tp5736198p5737153.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: SFTP Support to run GET PUT commands

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

Yes the camel-ftp components supports ftp, sftp and ftps.

sftp we use the JCraft JSCH library
http://www.jcraft.com/jsch/

On Wed, Jul 24, 2013 at 12:52 PM, deepak_a <an...@gmail.com> wrote:
> All,
>
> I am currently using Apace Camel for connecting to various end points -
> webservice, JMS, file etc.
> Now I have a requirement to PUT/GET files from an external system using
> SFTP.
>
> Is there support in Camel to run GET & PUT commands?
>
> e.g.
> put {local_file_name}  //<Directory>
> get //<directory> c:/myFile
>
> In addition I may need to use the following commands
>
> * CD
> * LS
>
> If it does support - would appreciate if someone can point to an example on
> how this in configured?
> I checked http://camel.apache.org/ftp.html but was not able to see if its
> possible to execute these commands.
>
> regards
> D
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/SFTP-Support-to-run-GET-PUT-commands-tp5736198.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
Email: cibsen@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen