How to copy a file on the FTP server to a directory on the same server in Java?

前端 未结 4 900
长情又很酷
长情又很酷 2020-12-05 08:25

I\'m using Apache Commons FTP to upload a file. Before uploading I want to check if the file already exists on the server and make a backup from it to a backup directory on

4条回答
  •  情深已故
    2020-12-05 08:55

    To backup at same Server (move), can you use:

    String source="/home/user/some";
    String goal  ="/home/user/someOther";
    FTPFile[] filesFTP = cliente.listFiles(source);
    
    clientFTP.changeWorkingDirectory(goal);  // IMPORTANT change to final directory
    
    for (FTPFile f : archivosFTP) 
       {
        if(f.isFile())
           {
            cliente.rename(source+"/"+f.getName(), f.getName());
           }
       }
    

提交回复
热议问题