51,411
社区成员
发帖
与我相关
我的任务
分享
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);
}
}