简体   繁体   中英

Java : Downloading file from a remote location using sftp

I have to download a file which is in remote location using SFTP on clicking a hyperlink . Am using JBOSS 5.1 as my Server and using struts2. I have implemented the below code and i found out the receiveBody() of the ConsumerTemplate is coming as null ? Can any one please guide me to the above issue ?

Code :

CamelContext ctx = new DefaultCamelContext();
                ConsumerTemplate consumer = ctx.createConsumerTemplate();
                String camel_ftp_uri = MessageFormat.format(CAMEL_FTP_PATTERN, ftp_mode, ftp_user, ftp_address, ftp_dir, ftp_options);
                System.out.println("camel_ftp_uri ::: "+camel_ftp_uri);

                Object obj= consumer.receiveBody(camel_ftp_uri);
                System.out.println("obj  ::"+obj);

when am printing the camel_ftp_uri am getting :camel_ftp_uri :::

ftp://ccc_uat1@1x.xxx.xx.xxx//from_ccc/file.txt?disconnect=true

I refered the below link in SOF :

How to retrieve a file from a server via SFTP?

Thanks in Advance

The Camel FTP component you have to configure the ftp uri with a starting directory, and then provide the file name to download as a seperate parameter. What you do wrong is that the starting directory is the file name.

This

ftp://ccc_uat1@1x.xxx.xx.xxx//from_ccc/file.txt?disconnect=true

Should be changed to

ftp://ccc_uat1@1x.xxx.xx.xxx//from_ccc/?disconnect=true&fileName=file.txt

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM