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):
    tar xzvf lftp-4.0.2.tar.gz
    cd lftp-4.0.2

    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:
    mirror -c /sourcedir/ /local/target/dir

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

  4. Now create another text file ( 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 "" to make it executable:
    chmod 755
  6. Now you can execute "" from command line:

    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 s
mirror --exclude cgi-bin --exclude stats -c /sourcedir/ /local/target/dir

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