简体   繁体   中英

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

This is my code

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();
}

which when is run returns

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

and then breaks on client.login("xxxxx", "xxxxx"); with Exception

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

Any idea why this happens?

java version is 1.4.2, ftp4j version is 1.7.2

The message is clear. You are talking SSL to a plaintext peer. Is there really an FTPS server at port 21 of that host?

please make sure you use the correct security settings, eg FTPClient.SECURITY_FTPS or FTPClient.SECURITY_FTPES

FTPS (FTP over implicit TLS/SSL) and FTPES (FTP over explicit TLS/SSL)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM