2015-04-06 130 views
0

我試圖在FTP服務器創建的路徑中獲取文件夾,但它不會返回任何內容,它將連接但不返回任何內容,如果我將服務器配置更改爲ftp,它將起作用。我正在使用FileZilla Server,其配置位於上方。如何使用java從FTPS服務器獲取文件?

SSL/TLS

標誌true啓用通過SSL/TLS支持(FTPS),FTP和SSL/TLS允許通過TLS明確的FTP設置

我的用戶配置爲:

扁「力量SSL用戶登錄「在FireZilla服務器的用戶配置常規中爲真。

服務器的有關連接日誌中得到一個消息,我不知道是否有幫助:

227進入被動模式需要

LIST

521 PROT P

PASV

227進入被動模式

NLST

521 PROT P需要

退出

我的示例類連接是上述與每一個權限:

公共類FTPClientExample2 {

public static void main(String[] args) 
{ 
    String server = "myip"; 
    int port = 2121; 
    String user = "joao"; 
    String pass = "1234"; 

    boolean error = false; 
    FTPSClient ftp = null; 
    try 
    { 
     ftp = new FTPSClient("SSL"); 
     ftp.setAuthValue("SSL"); 
     ftp.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out))); 

     int reply; 

     ftp.connect(server, port); 
     System.out.println("Connected to ftp.wpmikz.com.cn"); 
     System.out.print(ftp.getReplyString()); 

     // After connection attempt, you should check the reply code to verify 
     // success. 
     reply = ftp.getReplyCode(); 

     if (!FTPReply.isPositiveCompletion(reply)) 
     { 
      ftp.disconnect(); 
      System.err.println("FTP server refused connection."); 
      System.exit(1); 
     } 
     ftp.login(user, pass); 
     // ... // transfer files 
     ftp.setBufferSize(1000); 
     ftp.enterLocalPassiveMode(); 
     // ftp.setControlEncoding("GB2312"); 
     ftp.changeWorkingDirectory("/"); 
     ftp.changeWorkingDirectory("/ae"); //path where my files are 
     ftp.setFileType(FTP.BINARY_FILE_TYPE); 
     System.out.println("Remote system is " + ftp.getSystemName()); 

     String[] tmp = ftp.listNames(); //returns null 
     System.out.println(tmp.length); 
    } 
    catch (IOException ex) 
    { 
     System.out.println("Oops! Something wrong happened"); 
     ex.printStackTrace(); 
    } 
    finally 
    { 
     // logs out and disconnects from server 
     try 
     { 
      if (ftp.isConnected()) 
      { 
       ftp.logout(); 
       ftp.disconnect(); 
      } 
     } 
     catch (IOException ex) 
     { 
      ex.printStackTrace(); 
     } 
    } 
} 

}

任何想法有什麼不對?

謝謝大家!

+0

I M收到SSL錯誤後執行此操作。 javax.net.ssl.SSLHandshakeException:由對等關閉的連接 07-11 08:37:10.088 13124-15183/com.example.ftpdemo W/System.err:at com.android.org.conscrypt.NativeCrypto.SSL_do_handshake(本地方法) 07-11 08:37:10.088 13124-15183/com.example.ftpdemo W/System.err:at com.android.org.conscrypt.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:324) – PankajAndroid

回答

3

嘗試登錄

ftp.execPBSZ(0); 
    ftp.execPROT("P"); 
+0

它的工作原理,現在文件列表隨我的文件一起提供。非常感謝... –

+0

歡迎您 –

+0

請將答案標爲有效 –

相關問題