Lftp mirror

The FTP File Transfer Protocol protocol is quite old. It was created in 1971 and changed in 1972 which was closed to modern version. Development of the Internet endangered using FTP cause of the security weakness. Anyway this protocol is still usable in some production areas like WEB design, Post production, etc. As for me I prefer to stay away from FTP and prefer the modern secured protocols, but in some cases I have to use it for a while.

As a UNIX geek I prefer to use the terminal based applications. For FTP protocol the lftp program is a good choice. Just recently I learned that there exists a function mirror there which gives ability to mirror files and directories from the remote FTP server. To work with it is very simple:

The generic syntax in lftp interactive mode:

  mirror options
  mirror -c
  mirror -R
  -c, --continue (continue a mirror job if possible);
  -R, --reverse (reverse mirror (put files));
  -P, --parallel[=N] (download N files in parallel);
  -n, --only-newer (download only newer files (-c won't work))

First, you need to connect to the remote FTP server using the following syntax:

$ lftp username@ftp.server.com

To mirror all of the above files in the current directory, enter:

$ lftp username@ftp.server.com:~> mirror

I highly recommend that you start mirror job with resume option. This make sure if FTP mirror was failed due to network connection it will only download partial file:

$ lftp username@ftp.server.com:~> mirror -c

To download only newer files (-c won’t work):

$ lftp username@ftp.server.com:~> mirror -n

You can speed up FTP mirror operation by downloading files in parallel using the following syntax:

$ lftp username@ftp.server.com:~> mirror -p

You need to pass -R or --reverse option to do reverse mirror i.e. put all files from a local disk to a remote FTP server including sub-dirs and all files in it:

$ lftp username@ftp.server.com:~> mirror -R

Thanks for your attention.

comments powered by Disqus