如何用ftp服务器获取文件,如何使用java从FTPS服务器获取文件?

我试图在FTP服务器创建的路径中获取文件夹,但它不会返回任何内容,它将连接但不返回任何内容,如果我将服务器配置更改为ftp,它将起作用。我正在使用FileZilla Server,其配置位于上方。如何使用java从FTPS服务器获取文件?

SSL/TLS

标志true启用通过SSL/TLS支持(FTPS),FTP和SSL/TLS允许通过TLS明确的FTP设置

我的用户配置为:

扁“力量SSL用户登录“在FireZilla服务器的用户配置常规中为真。

服务器的有关连接日志中得到一个消息,我不知道是否有帮助:

227进入被动模式需要

LIST

521 PROT P

PASV

227进入被动模式

NLST

521 PROT P需要

退出

我的示例类连接是上述与每一个权限:

公共类FTPClientExample2 {

public static void main(String[] args)

{

String server = "myip";

int port = 2121;

String user = "joao";

String pass = "1234";

boolean error = false;

FTPSClient ftp = null;

try

{

ftp = new FTPSClient("SSL");

ftp.setAuthValue("SSL");

ftp.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out)));

int reply;

ftp.connect(server, port);

System.out.println("Connected to ftp.wpmikz.com.cn");

System.out.print(ftp.getReplyString());

// After connection attempt, you should check the reply code to verify

// success.

reply = ftp.getReplyCode();

if (!FTPReply.isPositiveCompletion(reply))

{

ftp.disconnect();

System.err.println("FTP server refused connection.");

System.exit(1);

}

ftp.login(user, pass);

// ... // transfer files

ftp.setBufferSize(1000);

ftp.enterLocalPassiveMode();

// ftp.setControlEncoding("GB2312");

ftp.changeWorkingDirectory("/");

ftp.changeWorkingDirectory("/ae"); //path where my files are

ftp.setFileType(FTP.BINARY_FILE_TYPE);

System.out.println("Remote system is " + ftp.getSystemName());

String[] tmp = ftp.listNames(); //returns null

System.out.println(tmp.length);

}

catch (IOException ex)

{

System.out.println("Oops! Something wrong happened");

ex.printStackTrace();

}

finally

{

// logs out and disconnects from server

try

{

if (ftp.isConnected())

{

ftp.logout();

ftp.disconnect();

}

}

catch (IOException ex)

{

ex.printStackTrace();

}

}

}

}

任何想法有什么不对?

谢谢大家!

+0

I M收到SSL错误后执行此操作。 javax.net.ssl.SSLHandshakeException:由对等关闭的连接 07-11 08:37:10.088 13124-15183/com.example.ftpdemo W/System.err:at com.android.org.conscrypt.NativeCrypto.SSL_do_handshake(本地方法) 07-11 08:37:10.088 13124-15183/com.example.ftpdemo W/System.err:at com.android.org.conscrypt.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:324) –