2012-08-24 85 views
0

我必須在單擊超鏈接時使用SFTP下載位於遠程位置的文件。我使用JBOSS 5.1作爲我的服務器並使用struts2。我已經實現了下面的代碼,並且我發現ConsumerTemplate的receiveBody()會變爲null? 任何人都可以請指導我以上問題?Java:使用sftp從遠程位置下載文件

代碼:

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); 

當我打印camel_ftp_uri我越來越:camel_ftp_uri :::

ftp://[email protected]//from_ccc/file.txt?disconnect=true

我refered在SOF以下鏈接:

How to retrieve a file from a server via SFTP?

在此先感謝

+0

這不是一個問題,這是一個「做我的工作對我來說」的要求。你已經嘗試了什麼,你遇到了什麼問題? – Omaha

+0

@Omaha謝謝你的關心。我已經清楚地提到了SFTP的新功能,並沒有得到他們在給出的鏈接中提到的內容 – Esh

+0

請閱讀http://serverfault.com/questions/176149/how-to-provide-a-web-interface-to- sftp服務器,看看是否有幫助 –

回答

1

駱駝FTP組件您必須配置ftp uri與一個起始目錄,然後提供文件名作爲一個單獨的參數下載。你做錯了什麼是起始目錄是文件名。

ftp://[email protected]//from_ccc/file.txt?disconnect=true 

應改爲

ftp://[email protected]//from_ccc/?disconnect=true&fileName=file.txt