使用Commons-net包中的FTPClient在获取文件列表时返回为空
int reply;
ftpClient.connect(ip, port);
// 下面三行代码必须要,而且不能改变编码格式
//ftp.setControlEncoding("GBK") ;
ftpClient.setControlEncoding("UTF-8");
FTPClientConfig conf = new FTPClientConfig(FTPClientConfig.SYST_NT);
ftpClient.configure(conf) ;
conf.setServerLanguageCode("zh");
ftpClient.login(username, password);// 登录
reply = ftpClient.getReplyCode();
if (!FTPReply.isPositiveCompletion(reply)) {
ftpClient.disconnect();
return success;
}
ftpClient.setDataTimeout(120000);
ftpClient.setBufferSize(204800);
ftpClient.changeWorkingDirectory("/video");
FTPFile[] fs = ftpClient.listFiles();//这个fs返回为空
boolean fileExists = false;
System.out.println("fileName is :" + fileName) ;
for (FTPFile ff : fs) {
System.out.println("ff's name is :" + ff.getName());
if (ff.getName().equals(fileName)) {
fileExists = true;
// 将文件保存到输出流outputStream中
ftpClient.retrieveFile(new String(ff.getName().getBytes("GBK"), "ISO-8859-1"), outputStream);
outputStream.flush();
outputStream.close();
}
}
ftpClient.logout();