Move entire directory and its contents to another

2019-06-05 04:38发布

问题:

As stated in the title, I would like to move a directory on a FTP Server to some other path on the same server. I want to accomplish this using Net::FTP but other solutions are also welcome.

Since there's no proper method for moving files or directories in Net::FTP Documentation, a solution involving copying the directory to another path and deleting the original would be preferable.

Please stay on topic and leave solutions related to the question.

回答1:

Well, I found the solution and it's quite simple. Files (& Directories) can be moved using the rename() method of the Net::FTP Class. Example:

ftp = Net::FTP.new("ftp.myserver.com","myusername","mypassword")
ftp.binary = true
ftp.passive = true

path1 = "/original/dir/path/"    # Dir to move
path2 = "/new/path/"             # New path of Dir

ftp.rename(path1, path2)

And that's it! This causes all files to move from one path to another on the same FTP Server.