2012-09-19 61 views
4

我在FTP服務器(ProFTPD 1.3.3a)上使用FTPClient讀取數據時遇到問題,需要在數據通道上進行加密。一切工作正常,沒有加密在其他服務器上。「使用Apache Commons在數據通道上使用550 SSL/TLS」FTPSClient

我的代碼是:

FTPSClient ftpsClient = new FTPSClient("TLS", false); 
log.debug("using TLS"); 
FTPClientConfig ftpClientConfig = new FTPClientConfig(FTPClientConfig.SYST_UNIX); 
ftpClientConfig.setServerLanguageCode("de"); 
ftpsClient.configure(ftpClientConfig); 
ftpsClient.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out))); // outputs all conversation to the console 
ftpsClient.connect(host, 21); 
ftpsClient.login(username, password); 
ftpsClient.enterLocalPassiveMode(); 
ftpsClient.changeWorkingDirectory(pathname); 
listNames = ftp.mlistDir(); 
ftpsClient.logout(); 

我從輸出得到的是

220 ProFTPD 1.3.3a Server (xxx) [xxx] 
AUTH TLS 
234 AUTH TLS successful 
USER xxx 
331 Password required for xxx 
PASS xxx 
230 User xxx logged in 
CWD /www/catalog 
250 CWD command successful 
PASV 
227 Entering Passive Mode (xxx). 
MLSD 
550 SSL/TLS required on the data channel 
QUIT 
221 Goodbye. 

任何想法如何FTPSClient配置爲使用TLS/SSL上的數據通道?您的幫助將不勝感激!

回答

11

在執行任何將通過數據通道傳輸數據的命令(如LIST)之前,您必須啓用數據通道加密。

此連接到服務器後添加到您的代碼:

// Set protection buffer size 
ftpClient.execPBSZ(0); 
// Set data channel protection to private 
ftpClient.execPROT("P"); 

至少,這解決了(使用proftpd的)我的問題。

+0

謝謝!這絕對解決了我的問題! – Randy

相關問題