Apache Commons FTPClient.listFiles [英] Apache Commons FTPClient.listFiles
问题描述
我正在使用 org.apache.commons.net.ftp.FTPClient
可以使用FTP服务器。我能够连接
,登录
, 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!