簡體   English   中英

ftp4j:client.login返回無法識別的SSL消息,純文本連接?

[英]ftp4j: client.login returns Unrecognized SSL message, plaintext connection?

這是我的代碼

try{
    TrustManager[] trustManager = new TrustManager[] { new X509TrustManager() {
        public X509Certificate[] getAcceptedIssuers() { return null; }
        public void checkClientTrusted(X509Certificate[] certs, String authType) {}
        public void checkServerTrusted(X509Certificate[] certs, String authType) {}
    } };

    SSLContext sslContext = null;

    sslContext = SSLContext.getInstance("TLS");
    sslContext.init(null, trustManager, new SecureRandom());
    SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();
    FTPClient client = new FTPClient();

    client.setSSLSocketFactory(sslSocketFactory);
    client.setSecurity(FTPClient.SECURITY_FTPES);

    client.connect("xxx.xxx.xxx", 21);
    System.out.println("Connected (" + client.isConnected() + ") to host " + client.getHost() + ":" + client.getPort());
    client.login("xxxxx", "xxxxx");            
}catch (Exception e) {
    e.printStackTrace();
}

運行時返回

Connected (true) to host xxx.xxx.xxx:21

然后在client.login(“ xxxxx”,“ xxxxx”);上斷開 有例外

javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?

知道為什么會這樣嗎?

Java版本是1.4.2,ftp4j版本是1.7.2

消息很清楚。 您正在與純文本對等方通信。 該主機的端口21上確實有一個FTPS服務器嗎?

請確保使用正確的安全設置,例如FTPClient.SECURITY_FTPSFTPClient.SECURITY_FTPES

FTPS(基於隱式TLS / SSL的FTP)和FTPES(基於顯式TLS / SSL的FTP)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM