0

这是我的代码

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

4

2 回答 2

0

信息很明确。您正在与纯文本对等方谈论 SSL。该主机的 21 端口真的有 FTPS 服务器吗?

于 2013-03-16T00:14:54.507 回答
0

请确保您使用正确的安全设置,例如 FTPClient.SECURITY_FTPSFTPClient.SECURITY_FTPES

FTPS(基于隐式 TLS/SSL 的 FTP)和 FTPES(基于显式 TLS/SSL 的 FTP)

于 2016-01-27T22:04:16.430 回答