Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am writing a Linux shell script to copy a local directory to a remote server (removing any existing files).

Local server: ftp and lftp commands are available, no ncftp or any graphical tools.

Remote server: only accessible via FTP. No rsync nor SSH nor FXP.

I am thinking about listing local and remote files to generate a lftp script and then run it. Is there a better way?

Note: Uploading only modified files would be a plus, but not required.

share|improve this question
ncftp is totally out the question ? Would be easiest imho. (and i know it'll do it as i use it that way) – Sirex Jan 11 '11 at 9:30
Sirex: I would rather do it with tools that come by default on RedHat. If lftp proves unusable, I will add a requirement for users to install ncftp. – Nicolas Raoul Jan 11 '11 at 9:40
The syntax for wput (a wget-like ftp-uploader): wput dir/ ftp://user:pass@host/dir – kenorb Jun 7 '15 at 12:47
up vote 18 down vote accepted

lftp should be able to do this in one step, in particular with lftp mirror:

EDIT: the lftp command syntax is confusing, original invocation I posted doesn't work. Try it like this:

lftp -e "mirror -R {local dir} {remote dir}" -u {username},{password} {host}

note the comments around the arguments to the -e switch.

share|improve this answer
+1 for tipping me that lftp's mirror mode works even if FXP is not available (I was convinced of the opposite after reading which says "both servers must support this protocol for this operation to succeed"). However, this particular command fails on my Ubuntu server: lftp: mirror: Name or service not known, Unknown command `-R'. – Nicolas Raoul Jan 11 '11 at 8:13
I reworded my answer with a better invocation of lftp, hopefully that helps. – Phil Hollenback Jan 11 '11 at 8:47
I finally gt it to work! It seems that you must switch remote and local for it to work. Please update and I will accept this answer. Here is a command line that works: lftp -e "mirror -R /tmp/mylocalfiles /var/www" -u remoteuser,remotepassword remoteserver – Nicolas Raoul Jan 12 '11 at 2:24
I think I saw in the lftp docs that you had to switch the local and remote dirs when using -R but I must have forgot. Updated my answer. – Phil Hollenback Jan 12 '11 at 2:29
How does it fail? Have you tried running 'lftp -vvv' for more verbose output to determine what it's trying to do? – Phil Hollenback Jan 12 '11 at 2:55

Based on Phil's idea of using lftp's mirror mode, this command does the trick:

lftp -c 'open -e "mirror /tmp/thedir ftp://nico:mypass@remotehost/~/destination/" ftp://nico:mypass@localhost'

A drawback is that it requires the local server to have an FTP server running.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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