我正在使用
请查看下面的代码片段:
org.apache.commons.net.ftp.FTPClient
在我的应用程序中与FTP服务器进行交互。我可以connect
,login
,pwd
和cwd
。然而,当我尝试list
文件时,它不会返回该目录中的文件列表,我确定那里有文件。我正在使用FTPFile[] listFiles()
方法,它返回一个空的FTPFile
数组。请查看下面的代码片段:
String hostname = properties.getProperty("FTP_SERVER");
String user = properties.getProperty("FTP_USER");
String passwd = properties.getProperty("FTP_PASSWD");
FTPClient client = new FTPClient();
client.connect(hostname);
client.login(user, passwd);
String reply = client.getStatus();
System.out.println(reply);
client.enterRemotePassiveMode();
client.changeWorkingDirectory("/uploads");
FTPFile[] files = client.listFiles();
System.out.println(files.length);
for (FTPFile file : files) {
System.out.println(file.getName());
}
String[] fileNames = client.listNames();
if (fileNames != null) {
for (String file : fileNames) {
System.out.println(file);
}
}
client.disconnect();