2013-01-22 160 views
1

我一直在尋找答案,但我發現最接近的只是責備服務器。如何使用FTP(E)S從服務器下載文件?

這是我的代碼,我的應用我使用的Zehon庫:

import com.zehon.BatchTransferProgressDefault; 
import com.zehon.FileTransferStatus; 
import com.zehon.exception.FileTransferException; 
import com.zehon.ftps.FTPsClient; 

public class UploadFolderSample { 
/** 
* Please refer to http://www.zehon.com/FTPs_samples.htm for its full source code 
* @param args 
*/ 
public static void main(String[] args) { 
    String host = "****"; 
    int port = 990; 
    String username = "******"; 
    String password = "*******"; 
    String sendingFolder = "*******/"; 
    String destFolder = "ftpes:******/"; 

    try { 
     com.zehon.ftps.FTPsClient ftps = new FTPsClient(host, port, username, password, false); 
     ftps.folderExists(destFolder); 
     int status = ftps.sendFolder(sendingFolder, destFolder, new BatchTransferProgressDefault()); 

     if(FileTransferStatus.SUCCESS == status){ 
      System.out.println(sendingFolder + " got ftps-ed successfully to folder "+destFolder); 
     } 
     else if(FileTransferStatus.FAILURE == status){ 
      System.out.println("Fail to ftps to folder "+destFolder); 
     } 
    } catch (FileTransferException e) { 
     e.printStackTrace(); 
    }  
} 

}

這是我的錯誤:

Thank you for using Zehon software (www.zehon.com). 
Please go to http://www.zehon.com/feedback.php to provide us your feedback about the product. 
Please go to http://www.zehon.com/feature_request.php to submit bugs or feature requests. 
com.zehon.exception.FileTransferException: org.apache.commons.net.ftp.FTPConnectionClosedException: Connection closed without indication. 
    at com.zehon.ftps.FTPsClient.folderExists(FTPsClient.java:1239) 
    at test.UploadFolderSample.main(UploadFolderSample.java:34) 
Caused by: org.apache.commons.net.ftp.FTPConnectionClosedException: Connection closed without indication. 
    at org.apache.commons.net.ftp.FTP.__getReply(FTP.java:313) 
    at org.apache.commons.net.ftp.FTP.__getReply(FTP.java:290) 
    at org.apache.commons.net.ftp.FTP._connectAction_(FTP.java:396) 
    at org.apache.commons.net.ftp.FTPClient._connectAction_(FTPClient.java:796) 
    at org.apache.commons.net.ftp.FTPSClient._connectAction_(FTPSClient.java:203) 
    at org.apache.commons.net.SocketClient.connect(SocketClient.java:172) 
    at org.apache.commons.net.SocketClient.connect(SocketClient.java:192) 
    at com.zehon.ftps.FTPsClient.getFTPSClient(FTPsClient.java:1444) 
    at com.zehon.ftps.FTPsClient.folderExists(FTPsClient.java:1236) 
    ... 1 more 

我真的可以使用一些幫助,我一直堅持FTPS的事情已經一個多星期了。

編輯(添加對話框): 這是我使用錯誤的端口時發生的情況,但至少它以這種方式顯示對話框。

> Thank you for using Zehon software (www.zehon.com). Please go to 
> http://www.zehon.com/feedback.php to provide us your feedback about 
> the product. Please go to http://www.zehon.com/feature_request.php to 
> submit bugs or feature requests. 220-FileZilla Server version 0.9.33 
> beta 220 Welcome by ***** AUTH TLS 234 Using authentication type TLS 
> USER ***** 331 Password required for ***** PASS ******* 230 Logged on 
> SYST 215 UNIX emulated by FileZilla PASV 227 Entering Passive Mode 
> (******) LIST ftpes:*****/ 550 PROT P required 220-FileZilla Server 
> version 0.9.33 beta 220 Welcome by **** AUTH TLS 234 Using 
> authentication type TLS USER **** 331 Password required for **** PASS 
> **** 230 Logged on Transfer start for file ****\test.txt MODE S 200 MODE set to S. TYPE I 200 Type set to I PASV 227 Entering Passive Mode 
> (*****) STOR ftpes:*****/test.txt 550 PROT P required Transfer error 
> *****/test.txt Transfer complete for file *****/test.txt Transfer start for file *****/test.txt MODE S 
+0

您是否與命令行FTP客戶端有相同的症狀?如果是,請嘗試使用'lftp'進行調試。 – fge

+0

@fge您的意思是客戶喜歡FileZilla嗎?因爲那麼答案是否定的,它通過其他客戶完美地工作。並感謝「lftp」提示:)。 –

+0

您可以用FileZilla可以執行的相同方式跟蹤對話框嗎? – fge

回答

2

存在顯式和隱式FTPS(FTP-over-SSL)。在第一種情況下,連接建立(通常)到端口21,然後發送一個命令在已建立的通道上協商SSL。隱式SSL意味着通過端口(通常)990進行連接,然後協商SSL,然後通過SSL安全通道發送常規命令(LOGIN等)。

如果你混合使用兩種模式(在非安全模式下連接到端口990或嘗試連接到端口21並立即啓動SSL握手),則什麼都不會起作用。

所以首先要做的是找出你需要使用的模式。然後你設置正確的端口並檢查你的庫是否支持所需的模式。

+0

如果我將它設置爲隱式和端口21,我得到此消息「com.zehon.exception.FileTransferException:javax .net.ssl.SSLException:無法識別的SSL消息,明文連接?「 我的老闆說他確定它是通過端口990顯式的,服務器給出的URL也是ftpes。 –

+1

@ArnoudAarnoudse更新的錯誤信息很有意義 - 顯式的FTPS可以正常工作,並且在嘗試打開數據連接時會出現問題。這可能是由服務器,組件或者兩者兼而有之 - 如果沒有調試和一些實驗,很難說。如果您使用PROT C(清除/非SSL模式用於數據通道) - 嘗試一下。 –

+0

那麼最終它可能實際上與服務器有關?服務器外包,我只是一名實習生,所以我沒有完全控制服務器,即使他們給我管理員帳戶。我會研究PROT C.我的老闆告訴我,如果我在明天之前無法完成,他會把它外包,但如果我曾經與(S)FTP(S)合作,這仍然是一個有用的學習經驗。 )。所以謝謝你的幫助:) –

相關問題