我正在尝试编写一个递归函数,它将一个目录完全上传到 ftp 服务器上。我需要检查我正在上传的目录是否已经存在,所以我需要检查该目录是否存在。但在 ftp4j 中,我目前无法找到任何此类功能。
代码:
if(!upclient.isConnected()){
upclient.connect(ftp_ip);
upclient.login(ftp_login, ftp_pass);
}
//i want to check here if the dir exit..if no i will create one
upclient.changeDirectory(ftpupload_path);
if (upclient.isConnected()) {
System.out.println("Connected to " + ftp_ip);
File local_dir=new File(local_path);
File[] uploadFiles=local_dir.listFiles();
for (File uploadfile : uploadFiles) {
if(uploadfile.isFile()){
System.out.println("Uploading" + upclient.currentDirectory() + "/" + uploadfile.getName());
upclient.upload(uploadfile);
} else if(uploadfile.isDirectory()){
uploadDir(ftp_ip, ftp_login, ftp_pass,upclient.currentDirectory()+"/"+uploadfile.getName(), uploadfile.getAbsolutePath());
upclient.changeDirectory(ftpupload_path);
}
}
}