[英]How to get files from FTPS server with java?
I'm trying to acess a folder in a path i created in a ftps server but it returns nothing, it's connecting but does not return anything, if i change the server configuration to just ftp it works. 我正在尝试在ftps服务器中创建的路径中访问一个文件夹,但它不返回任何内容,它在连接但不返回任何内容,如果我将服务器配置更改为ftp则可以正常工作。 I'm using FileZilla Server and the its configurations is above. 我正在使用FileZilla Server,其配置如上。
SSL/TLS SSL / TLS
Flag true Enable FTP over SSL/TLS support (FTPS) and Allow explicit FTP over TLS at SSL/TLS settings 标记为true启用SSL / TLS支持(FTPS)上的FTP并在SSL / TLS设置下允许通过TLS的显式FTP
My user configuration is: 我的用户配置是:
Flat "Force SSL for user login" is true at General of user configuration at FireZilla Server. 在FireZilla Server的用户配置常规中,平面“强制SSL用于用户登录”是正确的。
The server's log about the connection is getting a message, i dont know if it helps: 关于连接的服务器日志中收到一条消息,我不知道这是否有帮助:
227 Entering Passive Mode 227进入被动模式
LIST 清单
521 PROT P required 需要521 PROT P
PASV 肺动脉高压
227 Entering Passive Mode 227进入被动模式
NLST NLST
521 PROT P required 需要521 PROT P
Quit 放弃
My example class to connect is above with every permissions: 我上面连接的示例类具有每种权限:
public class FTPClientExample2 { 公共类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();
}
}
}
} }
Any idea what is wrong? 知道有什么问题吗?
Thank you all! 谢谢你们!
Try to execute this after the login 登录后尝试执行此操作
ftp.execPBSZ(0);
ftp.execPROT("P");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.