2013-03-25 63 views
0

剛剛確認FTPS服務器確實在使用Filezilla。很奇怪這個例外。無法識別的SSL消息

代碼

FTPSClient client = null; 
     try { 
      client = new FTPSClient(protocol, isImpicit); 
     } catch (NoSuchAlgorithmException e1) { 
      // TODO Auto-generated catch block 
      Logger.debug(e1); 
      e1.printStackTrace(); 
     } 
     client.setDataTimeout(timeoutInMillis); 
     //client.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out))); 

     System.out.println("################ Connecting to Server ################################"); 

     try 
     { 
      int reply; 
      System.out.println("################ Connect Call ################################"); 
      client.connect(ftpServer, ftpPort); 

      client.login(username, password); 

      System.out.println("################ Login Success ################################"); 

      //client.setFileType(FTP.BINARY_FILE_TYPE); 
      client.setFileType(FTP.NON_PRINT_TEXT_FORMAT); 
      client.execPBSZ(0); // Set protection buffer size 
      client.execPROT("P"); // Set data channel protection to private 
      client.enterLocalPassiveMode(); 

      System.out.println("Connected to " + server + "."); 
      reply = client.getReplyCode(); 

      if (!FTPReply.isPositiveCompletion(reply)) 
      { 
       client.disconnect(); 
       System.err.println("FTP server refused connection."); 
       System.exit(1); 
      } 

      client.listFiles(); 
      //boolean retrieved = client.retrieveFile(remoteFile, new FileOutputStream(localFile)); 
     } 
     catch (Exception e) 
     { 
      if (client.isConnected()) 
      { 
       try 
       { 
        client.disconnect(); 
       } 
       catch (IOException ex) 
       { 
        ex.printStackTrace(); 
       } 
      } 
      System.err.println("Could not connect to server."); 
      e.printStackTrace(); 
      return client; 
     } 
     finally 
     { 
      //client.disconnect(); 
      try { 
       client.logout(); 
      } catch (IOException e) { 
       // TODO Auto-generated catch block 
       Logger.debug(e); 
       e.printStackTrace(); 
      } 
      System.out.println("# client disconnected"); 
     } 
     return client; 

堆棧跟蹤

################ Connecting to Server ################################ 
################ Connect Call ################################ 
Could not connect to server. 
javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection? 
    at com.sun.net.ssl.internal.ssl.InputRecord.handleUnknownRecord(InputRecord.java:523) 
    at com.sun.net.ssl.internal.ssl.InputRecord.read(InputRecord.java:355) 
    at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:798) 
    at com.sun.net.ssl.internal.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1138) 
    at com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1165) 
    at com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1149) 
    at org.apache.commons.net.ftp.FTPSClient.sslNegotiation(FTPSClient.java:240) 
    at org.apache.commons.net.ftp.FTPSClient._connectAction_(FTPSClient.java:166) 
    at org.apache.commons.net.SocketClient.connect(SocketClient.java:178) 
    at myFtpService.getFtpConnection(myFtpService.java:61) 
+0

例外情況表明您正在與純文本服務器通信,或者至少某些不是直接SSL服務器的事情。 – EJP 2013-03-25 22:24:11

回答

0

集isImpicit爲false。看起來服務器期望顯式SSL連接(即整個連接將被SSL加密)。

相關問題