使用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();
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();
...全文
相关推荐
ftpclient所需jar包
ftpclient开发所需要的jar包,commons-net-1.4.1.zip,jakarta-oro-2.0.8.zip
org.apache.commons.net.ftp.FTPClient包
org.apache.commons.net.ftp.FTPClient包,不错,在实际项目和产品中使用过。
用org.apache.commons.net.ftp.FTPClient包实现简单文件下载
NULL 博文链接:https://vakinge.iteye.com/blog/487486
FTPClient开发工具类及使用示例
FTPClient开发工具类及FTPClient访问文件的部分使用示例
使用FTPClient实现文件的上传下载
NULL 博文链接:https://1017401036.iteye.com/blog/2266160


Java SE
