加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

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

发布时间:2020-12-15 00:02:40 所属栏目:Java 来源:网络整理
导读:我搜索了SO,谷歌搜索超过2天,没有找到任何帮助我的答案. 我无法通过TLS / SSL(FTPS)服务器连接到FTP.我正在使用SimpleFTP库,因为我可以连接没有SSL的FTP服务器,但无法连接FTPS. 它在第2行(ftp.connect)给我这个错误, SimpleFTP received an unknown response
我搜索了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).

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读