如何通过Java中的TLS / SSL(FTPS)服务器连接到FTP

搜索了SO,谷歌搜索超过2天,没有找到任何帮助我的答案.

我无法通过TLS / SSL(FTPS)服务器连接到FTP.我正在使用SimpleFTP库,因为我可以连接没有SSL的FTP服务器,但无法连接FTPS.

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

SimpleFTP received an unkNown response when connecting to the FTP server:
220———- Welcome to 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();

解决方法

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,请使用新的FTPSClient(true).

相关文章

应用场景 C端用户提交工单、工单创建完成之后、会发布一条工...
线程类,设置有一个公共资源 package cn.org.chris.concurre...
Java中的数字(带有0前缀和字符串)
在Java 9中使用JLink的目的是什么?
Java Stream API Filter(过滤器)
在Java中找到正数和负数数组元素的数量