我目前正在尝试从FTP服务器中提取文件,但我在这个过程中遇到了麻烦。下面的代码是唯一的部分工件:</ p>
问题:当LIST命令被推送到FTP服务器时,它只是挂起而没有超时,错误输出或抛出异常。我实际上不小心让这个过程在周末运行,并且整个时间都挂了。我已经包含了从FTP服务器输出的回复字符串,但我觉得有一些我错过的特定错误信息可以帮助我查明这个错误。
问题:
我们在三种不同的环境中尝试过这种代码 - 一种是远程本地代码。任何有关这方面的帮助都会非常感激,因为我和我团队中一位资深的开发人员都很难过。谢谢你的时间!
主要方法:
FTPSClient ftp = new FTPSClient();
boolean error = false;
try {
int reply;
ftp.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out), true));
ftp.connect("SITE_NAME", 991);
ftp.setFileType(FTP.BINARY_FILE_TYPE);
System.out.println("Set file type to binary");
ftp.sendCommand("PBSZ 0");
ftp.sendCommand("PROT P");
ftp.enterLocalPassiveMode();
System.out.println("Set mode to passive (local).");
//ftp.enterRemotePassiveMode();
//System.out.println("Set mode to passive.");
boolean success = ftp.login("USERNAME", "PASSWORD");
if (!success) {
System.out.println("Could not login to the server");
return;
} else {
System.out.println("LOGGED IN SERVER");
}
ftp.setBufferSize(1024 * 1024);
//ftp.sendCommand("OPTS UTF8 ON");
String directory = ftp.printWorkingDirectory();
System.out.println("Working directory: " + directory);
int timeout = ftp.getConnectTimeout();
System.out.println("Timeout Length: " + timeout);
FTPFile[] list = ftp.listFiles();
System.out.println("Generate List of Files");
int length = list.length;
System.out.println("Length: " + length);
ftp.logout();
} catch(IOException e) {
error = true;
e.printStackTrace();
} finally {
if(ftp.isConnected()) {
try {
ftp.disconnect();
} catch(IOException ioe) {
// do nothing
}
}
//System.exit(error ? 1 : 0);
}
}
协议命令侦听器的输出:
220 Microsoft FTP Service
AUTH TLS
234 AUTH command ok. Expecting TLS Negotiation.
TYPE I
200 Type set to I.
Set file type to binary
PBSZ 0
200 PBSZ command successful.
PROT P
200 PROT command successful.
Set mode to passive (local).
USER *******
331 Password required
PASS *******
230 User logged in.
LOGGED IN SERVER
PWD
257 "/" is current directory.
Working directory: /
Timeout Length: 0
SYST
215 Windows_NT
PASV
227 Entering Passive Mode (204,179,168,88,195,91).
LIST
125 Data connection already open; Transfer starting.