java FTP下载 部分文件为空

renzuguo 2018-07-29 12:57:55
测试下面的代码,不知道为什么子文件夹里面的文件都可以成功下载,最外层的文件下载下来只有文件名,大小为0Kb

public void DownFile(String remotePath,String localPath) {
try {
ftp.changeWorkingDirectory(remotePath); // 转移到FTP服务器目录
FTPFile[] fs = ftp.listFiles();
for (FTPFile ff : fs) {
if(ff.isFile()){
System.out.println(remotePath);
System.out.println(localPath);
File localFile = new File(localPath+"\\"+ff.getName());
if(!localFile.exists()){
System.out.println("文件不存在,下载");
OutputStream is = new FileOutputStream(localFile);
ftp.retrieveFile(ff.getName(), is);
is.close();
}else{
System.out.println("文件存在,不用下载");
}
}else{
File myPath = new File(localPath+"\\"+ff.getName());
if(!myPath.exists()){
myPath.mkdir();
}
DownFile(remotePath+ff.getName()+"/",localPath+"\\"+ff.getName());
}
}
} catch (IOException ex) {
Logger.getLogger(PDOAupdate.class.getName()).log(Level.SEVERE, null, ex);
}
}
...全文
604 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

51,412

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧