【问题标题】:How to connect to FTP over TLS/SSL (FTPS) server in Java如何在 Java 中通过 TLS/SSL (FTPS) 服务器连接到 FTP
【发布时间】:2016-07-18 02:40:31
【问题描述】:

我无法通过 TLS/SSL (FTPS) 服务器连接到 FTP。我正在使用 SimpleFTP 库,因为我能够在没有 SSL 的情况下连接 FTP 服务器,但无法连接 FTPS。

它在第 2 行 (ftp.connect) 给了我这个错误,

SimpleFTP 在连接 FTP 服务器时收到未知响应:
220--------- 欢迎使用 Pure-FTPd [privsep] [TLS] ----------

我正在使用下面的代码

SimpleFTP ftp = new SimpleFTP();

// Connect to an FTP server on port 21.
ftp.connect("xxx.xxx.xxx.xxx", 21, "username", "pwd");
//getting error at (ftp.connect) above line

// Set binary mode.
ftp.bin();

// Change to a new working directory on the FTP server.
ftp.cwd("web");
ftp.disconnect();

【问题讨论】:

    标签: java ssl ftp ftps


    【解决方案1】:

    SimpleFTP 类/库根本不支持 TLS/SSL。


    请改用Apache Commons Net library 中的FTPSClient class

    查看official example for the FTPClient class 并将FTPClient 替换为FTPSClient

    FTPSClient ftpClient = new FTPSClient();
    ftpClient.connect(host);
    ftpClient.login(user, password);
    

    FTPSClient 类默认为显式 TLS/SSL(推荐)。在极少数情况下,您需要隐式 TLS/SSL,请使用 new FTPSClient(true)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-05-24
      • 1970-01-01
      • 1970-01-01
      • 2015-05-24
      相关资源
      最近更新 更多