如何通过Java中的TLS / SSL(FTPS)服务器连接到FTP [英] How to connect to FTP over TLS/SSL (FTPS) server in Java

查看:3452
本文介绍了如何通过Java中的TLS / SSL(FTPS)服务器连接到FTP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我在通过TLS / SSL连接到FTP时遇到困难( FTPS)服务器。我通过能够连接FTP服务器而不使用SSL但无法连接FTPS来使用SimpleFTP库。



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


当连接到FTP服务器时,SimpleFTP收到未知响应:

220 -------- - 欢迎使用Pure-FTPd [privsep] [TLS] ----------


并且正在使用以下版本代码

  SimpleFTP ftp = new SimpleFTP(); 

//连接到端口21上的FTP服务器。
ftp.connect(xxx.xxx.xxx.xxx,21,username,pwd);
//在(ftp.connect)行上面获得错误

//设置二进制模式。
ftp.bin();

//转到FTP服务器上的新工作目录。
ftp.cwd(web);
ftp.disconnect();


解决方案

SimpleFTP

使用 FTPSClient Apache Commons Net库中的



请参阅 FTPClient class的官方示例,只需将 FTPClient 替换为 FTPSClient

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






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


I searched SO, googled more than 2 days and did not found any answer that helps me.

I'm stuck in connecting to FTP over TLS/SSL (FTPS) server. I am using SimpleFTP library through am able to connect FTP server without SSL but could not connect FTPS.

It is giving me this error at line 2 (ftp.connect),

SimpleFTP received an unknown response when connecting to the FTP server:
220---------- Welcome to 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.


Use the FTPSClient class from the Apache Commons Net library instead.

See the official example for the FTPClient class and just substitute the FTPClient with the FTPSClient.

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


The FTPSClient class defaults to an explicit TLS/SSL (recommended). In a rare case you need an implicit TLS/SSL, use new FTPSClient(true).

这篇关于如何通过Java中的TLS / SSL(FTPS)服务器连接到FTP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆