On the remote FTP server, I have a set of files in the directory remote.dir1
. I would like to move all the files in that directory to remote.dir2
.
I am using lftp
and was trying something like this:
lftp> mv remote.dir1/* remote.dir2/
It does not work and displays: Access failed: 550 remote.dir1/*: The filename, directory name, or volume label syntax is incorrect.
I also tried:
lftp> glob -a mv remote.dir1/* remote.dir2/
which displays the usage message: Usage: mv <file1> <file2>
However, moving single file works: lftp> mv remote.dir1/file1 remote.dir2/
As a last resort, we can construct a file containing a set of lftp mv
commands and source
it.
Are there any solutions I am not aware of?
Or, are there any capable command line tools for the task?
Edit: I am restricted to FTP environment, so only solutions using FTP are acceptable due to the environmental constraint.
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:
Or, the one-linerTM:
It appears that lftp only supports the
glob
syntax with commands accepting a single argument, somv
, 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.rsync is great for moving files from one machine to another (or even between the same machine).
This command supplies a private key, and connects to a machine. It grabs files from the remote directory, and copies them to the local directory. You can also do the reverse of this by switching the source and destination.
A bit late to the party, but in July 2017 the "mmv" command was added to lftp.
So, in your case:
I thought FTP was more or less dead. It's been close to 5 years since I've used it, and it was on the way out 10 years ago.
That said, I always found the ncftp family of command line tools very friendly, and I expect this would "just work".
I'm not going to set up an FTP server for the purposes of verifying this, but give it a try. There's a lot else to like about ncftp (At least from version 2 on).