[英]How to connect to FTP over TLS/SSL (FTPS) server in Java
I'm stuck in connecting to FTP over TLS/SSL (FTPS) server.我一直在通过 TLS/SSL (FTPS) 服务器连接到 FTP。 I am using SimpleFTP library through am able to connect FTP server without SSL but could not connect FTPS.
我正在使用 SimpleFTP 库,因为我能够在没有 SSL 的情况下连接 FTP 服务器,但无法连接 FTPS。
It is giving me this error at line 2 (ftp.connect),它在第 2 行(ftp.connect)给了我这个错误,
SimpleFTP received an unknown response when connecting to the FTP server:
SimpleFTP 连接到 FTP 服务器时收到未知响应:
220---------- Welcome to Pure-FTPd [privsep] [TLS] ----------220---------- 欢迎使用 Pure-FTPd [privsep] [TLS] ----------
and am using below code并且正在使用下面的代码
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();
The SimpleFTP
class/library does not support TLS/SSL at all. SimpleFTP
类/库根本不支持 TLS/SSL。
Use the FTPSClient
class from the Apache Commons Net library instead.请
FTPSClient
Apache Commons Net 库中的FTPSClient
类。
See the official example for the FTPClient
class and just substitute the FTPClient
with the FTPSClient
.请参阅
FTPClient
类的官方示例,只需将FTPClient
替换为FTPSClient
。
FTPSClient ftpClient = new FTPSClient();
ftpClient.connect(host);
ftpClient.login(user, password);
The FTPSClient
class defaults to an explicit TLS/SSL (recommended). FTPSClient
类默认为显式 TLS/SSL(推荐)。 In a rare case you need an implicit TLS/SSL, use new FTPSClient(true)
.在极少数情况下,您需要隐式 TLS/SSL,请使用
new FTPSClient(true)
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.