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.
lftp should be able to do this in one step, in particular with
lftp mirror
:The lftp command syntax is confusing, original invocation I posted doesn't work. Try it like this:
note the quotes around the arguments to the
-e
switch.This worked for me, many other attempts were failing. Once in lftp, more info available via:
Based on Phil's idea of using lftp's mirror mode, this command does the trick:
A drawback is that it requires the local server to have an FTP server running.
Rather than the common answer of using mirroring, I often find it preferable to use
mput
, especially if there are several directories to transfer.For example, given the following:
... if the goal is to transfer directories
mydir[2-4]
, you can either clunkily use themirror
command:... and repeat serially for
mydir3
andmydir4
... or you can usemput
as follows:... and be done. The
-d
option is key here:Finally got the answer!!! Create shell script ftpmirror.sh
If lftp package is not installed the installed it using yum.