7

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.

2
  • When you say 'it does not work' are you getting any errors? Aug 21, 2013 at 7:56
  • yes, in this particular case i'm using lftp, it throws me this line: Access failed: 550 remote.dir1/*: The filename, directory name, or volume label syntax is incorrect.
    – cychoi
    Aug 21, 2013 at 8:01

5 Answers 5

5

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
3

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.

0

rsync is great for moving files from one machine to another (or even between the same machine).

rsync -avz -e "ssh -i /key/path/key.rsa" user@1.2.3.4:/path/on/remote/server/ /path/on/local/server

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.

4
  • 2
    The question is about using an FTP client to move a server directory's files
    – the-wabbit
    Aug 21, 2013 at 7:50
  • OP also stated: "Are there any solutions I am not aware of? Or, are there any capable command line tools for the task?". rsync sounds pretty capable to me. Aug 21, 2013 at 7:51
  • The question is about moving files. OP happened to try FTP but that's not the only way. Aug 21, 2013 at 7:53
  • @DrewKhoury Sorry for not being clear enough. I am restricted to FTP protocol only. One of reasons is because the FTP server is a Windows machine. I will update the question on that. Thanks :)
    – cychoi
    Aug 21, 2013 at 7:54
0

A bit late to the party, but in July 2017 the "mmv" command was added to lftp.

Usage: mmv [OPTS] <files> <target-dir>
Move <files> to <target-directory> with wildcard expansion
 -O <dir>  specifies the target directory (alternative way)

So, in your case:

mmv remote.dir1/* remote.dir2/
-1

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).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.