Ftp – How to upload a directory recursively to an FTP server by just using ftp or lftp

directoryftprecursivesynchronizationupload

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.

Best Answer

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:

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

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