How to move a set of files on the same FTP server?
Solution 1:
For documentation purpose, I will post the steps I used to complete the task. Any better solutions are much appreciated. ;-)
Note: this solution uses the lftp
FTP client. You may have to install it on your machine before you can proceed.
Solution:
lftp> renlist remote.dir1/ | "sed 's/\(.*\)/mv \"\1\" \"remote.dir2\/\"/'" > list
lftp> source list
lftp> !rm list
Or, the one-linerTM:
lftp> renlist remote.dir1/ | "sed 's/\(.*\)/mv \"\1\" \"remote.dir2\/\"/'" > list && source list && !rm list
Solution 2:
It appears that lftp only supports the glob
syntax with commands accepting a single argument, so mv
, which requires two, is out.
With FTP, your server might allow for extended commands, especially the execution of a limited command set via SITE EXEC
or similar means - check the FTP server's documentation, its help (SITE HELP
) or the login banner. These however are not standardized, so if the solution needs to be FTP-server-agnostic, scripting based on the output of the file list seems like the best idea.