问题描述
我正在使用 org.apache.commons.net.ftp.FTPClient
在我的一个应用程序中使用 FTP 服务器.我能够connect
、login
、pwd
和cwd
.但是,当我尝试 list
文件时,它不会返回该目录中的文件列表,我确定其中有文件.我正在使用方法 FTPFile[] listFiles()
,返回一个空数组FTPFile
.
I am using org.apache.commons.net.ftp.FTPClient
in one of my applications to work with a FTP server. I am able to connect
, login
, pwd
and cwd
. However, when I try to list
the files it doesn't return the list of files in that directory, where I know for sure that there are files. I am using the method FTPFile[] listFiles()
, it returns an empty array of FTPFile
.
请在我尝试此操作的代码片段下方找到:
Please find below the code snippet where I am trying this:
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();
推荐答案
这似乎与我遇到(并已解决)的问题相同,请参阅此答案:
This seems like the same issue I had (and solved), see this answer:
Apache Commons Net FTPClient 和 listFiles()
这篇关于Apache Commons FTPClient.listFiles的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!