How to synchronize your files by ftp

If you are looking for a solution how to make an automatic copy, backup or synchronized mirror of your files or even a complete website, this article is for you. This solution will copy only new or changed files (incremental copy). So full copy is made only at first run. To make it work you will need ftp or sftp access to server where your files are stored and ssh (or telnet) access to account that you want your files to be mirrored to. To make it work follow this steps:

  1. Make sure that you have LFTP client installed on your system. You can get it from your Linux distribution repository or get the source from LFTP website and compile like this (if you don't have root access ask your administrator to do it):
    wget http://tactical.wiretapped.net/mirrors/lftp/
    tar xzvf lftp-4.0.2.tar.gz
    cd lftp-4.0.2
    ./configure
    make

    And as root of your system:

    make install

    If you won't get any errors during this steps you will have LFTP installed.

  2. Prepare the directory where you will want to have your mirrored files and change your current dir to it:
    mkdir sync
    cd ./sync
  3. Create sync file (yoursyncname.lftp) with your favorite text editor and put there this instructions:
    open ftp://yourlogin:yourpassword@sorcedomain.com:22
    mirror -c /sourcedir/ /local/target/dir
    exit

    Of course you will need to change "yourlogin", "yourpassword" and "sourcedomain.com" with your ftp login details. Please save this file.

  4. Now create another text file (yoursyncname.sh) that will execute previous commands. Put there this line:
    lftp -f /local/target/yoursyncname.lftp

    Don't forget to change the path to "yoursyncname.lftp" file!

  5. Chmod "yoursyncname.sh" to make it executable:
    chmod 755 yoursyncname.sh
  6. Now you can execute "yoursyncname.sh" from command line:
    ./yoursyncname.sh

    or put it as a cronjob to make regular mirror.

TIP: If you need to exclude any files or subdirectories from being copied from source directory, you may modify "yoursyncname.lftp" to something like this:

open sftp://yourlogin:yourpassword@sorcedomain.com:22
mirror --exclude cgi-bin --exclude stats -c /sourcedir/ /local/target/dir
exit

1 Responses to “How to synchronize your files by ftp”


  • Thanks for this step by step guide.. I’ve been designing sites for about 10 months now and using ftp to synchronize my files has been something I’ve overlooked. This should make life easier for me.

Leave a Reply