Softpanorama

May the source be with you, but remember the KISS principle ;-)
Home Switchboard Unix Administration Red Hat TCP/IP Networks Neoliberalism Toxic Managers
(slightly skeptical) Educational society promoting "Back to basics" movement against IT overcomplexity and  bastardization of classic Unix

Using lftp mirror command

Lftp mirror command does not replace recursive copy that is available in NcFTP. It is really mirror command and it does a lot of extra homework directed at this goal, which is unnecessary and annoying if you just need to send directory tree to the other server.


Top Visited
Switchboard
Latest
Past week
Past month

NEWS CONTENTS

Old News ;-)

Using lftp mirror to copy your website files

InMotion Hosting

Written by Jacob Nicholson

Views: 12,422

Published: Jan 28, 2013

Comments: 3

In this article I'm going to teach you how to use the lftp mirror command in order to copy your website files from another web host to your VPS (Virtual Private Server) or dedicated server with InMotion Hosting.

The Linux lftp command is a sophisticated FTP/HTTP client that is also capable of being able to mirror the entire contents of a remote website to your local server, or vice-versa. Using the lftp command on your server can help save you time when copying website files from a remote server.

You can directly transfer the files right to your server, instead of having to first locally copy files to your desktop, just to upload them again to your server. Typically web hosts will have higher bandwidth connections than your residential Internet connection, so directly transferring files between two servers with lftp is an ideal method to use if you've got a lot of files to transfer.

In order to follow along with the steps below you'll need to have either a VPS or dedicated server so that you have SSH access to your server in order to run the lftp mirror command.

lftp mirror remote files to your server

Using the steps below I'll show you how to quickly connect to a remote server where you might have website files stored, and then mirror the entire contents of that website to your server using the lftp mirror commands.

  1. Login to your server via SSH with the cPanel user you'd like to copy remote files to.
  2. After logging into SSH run the following command to get to your public directory:

    cd ./public_html/

    You can now run the following command to ensure you're in the right directory:

    pwd

    You should get back something like this:

    /home/userna5/public_html

    In most cases your /public_html/ directory should be empty if you haven't placed any files on the server yet. If you wanted to do your file transfer to another directory such as a sub-directory, you would want to use the cd command again to end up in that directory.

  3. In this example we're going to connect to our old remote server at example.com using the FTP username userna5 and the password of passWORD. Run the following command to begin our lftp session to this remote server:

    lftp -u userna5,passWORD example.com

    If your FTP password includes special characters such as $ or ) you'd want to leave off the password like this, then type it in manually when prompted:

    lftp -u userna5 example.com

    In some cases certain servers will now allow you to connect with lftp with the default settings, you can try the following to connect to these type of servers:

    lftp -u userna5,passWORD example.com -e "set ftp:ssl-allow off"

    You should end up at the lftp prompt when you've successfully connected to the remote server, it would look like this:

    lftp [email protected]:~>

  4. Now that you have a FTP connection established to the remote server, the next step is to change directories into the remote directory with your files. To view all of the folders on the remote server you can use the following command:

    ls

    It should give you back something similar to this:

    lrwxrwxrwx 1 userna5 userna5 33 Jul 16 2011 access-logs -> /usr/local/apache/domlogs/userna5
    drwxr-xr-x 2 userna5 userna5 4096 Nov 20 2010 backup
    drwxr-x--- 4 userna5 12 4096 Jan 28 14:14 etc
    drwxr-x--x 11 userna5 userna5 20480 Jan 10 12:52 mail
    drwxr-x--- 11 userna5 99 4096 Jan 28 14:15 public_html
    drwxr-xr-x 10 userna5 userna5 4096 Jan 22 13:56 tmp
    lrwxrwxrwx 1 userna5 userna5 11 Jul 16 2011 www -> public_html

    In this case our website files are stored in the /public_html/ directory so we can run the following command to get to this directory:

    cd public_html

  5. Now that you've changed into the remote directory where you'd like to mirror all of the files to your server from, run the following command to begin the file transfer:

    mirror -c

    This uses the lftp mirror command to mirror the entire remote directory to our current local directory that we changed to prior to starting the transfer. The -c option is for continue and allows the mirror to continue from a previously failed transfer.

    After the file transfer has completed you should see the status of the full transfer which looks something like this:

    lftp [email protected]:/public_html> mirror -c
    Total: 175 directories, 1316 files, 0 symlinks
    New: 1316 files, 0 symlinks
    20750001 bytes transferred in 20 seconds (1010.8K/s)
    To be removed: 1 directory, 0 files, 0 symlinks

  6. Type either exit or quit to leave the lftp session:

    lftp [email protected]:/public_html> exit

You should now know how to use the lftp mirror command on your VPS or dedicated server in order to transfer over website files from a remote server.

lftp Command Mirror Files and Directories

August 5, 2012 | nixCraft | 8 comments

How do I mirror files from remote ftp server using lftp command? How do put the entier directory from a local disk to a remote ftp server (reverse mirror) using lftp command under Linux and Unix like operating systems?

Tutorial details
Difficulty Easy
Root privileges No
Requirements lftp ftp client

lftp command is a file transfer program that allows sophisticated ftp, http and other connections to other hosts. lftp command has builtin mirror which can download or update a whole directory tree. There is also reverse mirror (mirror -R) which uploads or updates a directory tree on server. Mirror can also synchronize directories between two remote servers, using FXP if available. The syntax is:

 
mirror
mirror options
mirror -c
mirror -R
 
Example: How to mirror files from a remote ftp server (get files)

First, you need to connect to the remote ftp server using the following syntax:
lftp ftp.cyberciti.biz
Type username and password:

lftp ftp.cyberciti.biz:~> user [email protected]

Sample outputs:

Password:
lftp [email protected]@rawlogs.bitgravity.com:~>

Type ls command to see a list of files:

lftp ftp.cyberciti.biz:~> ls

Sample outputs:

-rw-r--r--    1 80       www      36809419 Jun 24 23:59 2012-06-24.log.gz
-rw-r--r--    1 80       www      100912271 Jun 25 23:59 2012-06-25.log.gz
-rw-r--r--    1 80       www      102926055 Jun 26 23:59 2012-06-26.log.gz

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

lftp ftp.cyberciti.biz:~> mirror

With mirror lftp command you can specify source directory to local target directory. If target directory ends with a slash, the source base name is appended to target directory name. Source and/or target can be URLs pointing to directories. The syntax is:

lftp ftp.cyberciti.biz:~> mirror source target

OR

lftp ftp.cyberciti.biz:~> mirror logs/ /data/wwwlogs

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 ftp.cyberciti.biz:~> mirror -c source target

OR

lftp ftp.cyberciti.biz:~> mirror --continue

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

lftp ftp.cyberciti.biz:~> mirror --only-newer

OR

lftp ftp.cyberciti.biz:~> mirror -n

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

lftp ftp.cyberciti.biz:~> mirror -p

To download 10 files in parallel, enter:

lftp ftp.cyberciti.biz:~> mirror --parallel=10

You can use pget to transfer every single file:

lftp ftp.cyberciti.biz:~> mirror -c  --use-pget-n=10
Example: How to reverse mirror files to a remote ftp server (put files)

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. In this example reverse mirror /home/project/website/version5/ to a remote ftp server called ftp.cyberciti.biz:
First, you need to connect to the remote ftp server using the following syntax:
lftp ftp.cyberciti.biz
Type username and password:

lftp ftp.cyberciti.biz:~> user [email protected]

Sample outputs:

Password:
lftp [email protected]@rawlogs.bitgravity.com:~>

Change local directory to /home/project/website/version5/:

lftp ftp.cyberciti.biz:~> lcd /home/project/website/version5/

Sample outputs:

lcd ok, local cwd=/home/project/website/version5

To upload, enter:

lftp ftp.cyberciti.biz:~> mirror -R

OR set local directory and remote upload directory as follows:

lftp ftp.cyberciti.biz:~> mirror -R /home/vivek/projects/website/version10 /var/www/html

When using -R, the first directory is local and the second is remote. If the second directory is omitted, base name of first directory is used. If both directories are omitted, current local and remote directories are used. If target directory ends with a slash (except root directory) then base name of source directory is appended. To quit from ftp session type:

lftp ftp.cyberciti.biz:~> quit
A complete list of lftp mirror command options

Taken from the man page:

 
            -c, --continue      continue a mirror job if possible
            -e, --delete        delete files not present at remote site
                --delete-first       delete old files before transferring new ones
                --depth-first        descend into subdirectories before transferring files
            -s, --allow-suid         set suid/sgid bits according to remote site
                --allow-chown   try to set owner and group on files
                --ascii         use ascii mode transfers (implies --ignore-size)
                --ignore-time        ignore time when deciding whether to download
                --ignore-size        ignore size when deciding whether to download
                --only-missing  download only missing files
                --only-existing download only files already existing at target
            -n, --only-newer    download only newer files (-c won't work)
                --no-empty-dirs don't create empty directories (implies --depth-first)
            -r, --no-recursion  don't go to subdirectories
                --no-symlinks   don't create symbolic links
            -p, --no-perms      don't set file permissions
                --no-umask      don't apply umask to file modes
            -R, --reverse       reverse mirror (put files)
            -L, --dereference   download symbolic links as files
            -N, --newer-than=SPEC    download only files newer than specified time
                --on-change=CMD      execute the command if anything has been changed
                --older-than=SPEC    download only files older than specified time
                --size-range=RANGE   download only files with size in specified range
            -P, --parallel[=N]  download N files in parallel
                --use-pget[-n=N]     use pget to transfer every single file
                --loop          loop until no changes found
            -i RX, --include RX include matching files
            -x RX, --exclude RX exclude matching files
            -I GP, --include-glob GP include matching files
            -X GP, --exclude-glob GP exclude matching files
            -v, --verbose[=level]    verbose operation
                --log=FILE      write lftp commands being executed to FILE
                --script=FILE        write lftp commands to FILE, but don't execute them
                --just-print, --dry-run   same as --script=-
                --use-cache          use cached directory listings
            --Remove-source-files    remove files after transfer (use with caution)
            -a             same as --allow-chown --allow-suid --no-umask
>



Etc

Society

Groupthink : Two Party System as Polyarchy : Corruption of Regulators : Bureaucracies : Understanding Micromanagers and Control Freaks : Toxic Managers :   Harvard Mafia : Diplomatic Communication : Surviving a Bad Performance Review : Insufficient Retirement Funds as Immanent Problem of Neoliberal Regime : PseudoScience : Who Rules America : Neoliberalism  : The Iron Law of Oligarchy : Libertarian Philosophy

Quotes

War and Peace : Skeptical Finance : John Kenneth Galbraith :Talleyrand : Oscar Wilde : Otto Von Bismarck : Keynes : George Carlin : Skeptics : Propaganda  : SE quotes : Language Design and Programming Quotes : Random IT-related quotesSomerset Maugham : Marcus Aurelius : Kurt Vonnegut : Eric Hoffer : Winston Churchill : Napoleon Bonaparte : Ambrose BierceBernard Shaw : Mark Twain Quotes

Bulletin:

Vol 25, No.12 (December, 2013) Rational Fools vs. Efficient Crooks The efficient markets hypothesis : Political Skeptic Bulletin, 2013 : Unemployment Bulletin, 2010 :  Vol 23, No.10 (October, 2011) An observation about corporate security departments : Slightly Skeptical Euromaydan Chronicles, June 2014 : Greenspan legacy bulletin, 2008 : Vol 25, No.10 (October, 2013) Cryptolocker Trojan (Win32/Crilock.A) : Vol 25, No.08 (August, 2013) Cloud providers as intelligence collection hubs : Financial Humor Bulletin, 2010 : Inequality Bulletin, 2009 : Financial Humor Bulletin, 2008 : Copyleft Problems Bulletin, 2004 : Financial Humor Bulletin, 2011 : Energy Bulletin, 2010 : Malware Protection Bulletin, 2010 : Vol 26, No.1 (January, 2013) Object-Oriented Cult : Political Skeptic Bulletin, 2011 : Vol 23, No.11 (November, 2011) Softpanorama classification of sysadmin horror stories : Vol 25, No.05 (May, 2013) Corporate bullshit as a communication method  : Vol 25, No.06 (June, 2013) A Note on the Relationship of Brooks Law and Conway Law

History:

Fifty glorious years (1950-2000): the triumph of the US computer engineering : Donald Knuth : TAoCP and its Influence of Computer Science : Richard Stallman : Linus Torvalds  : Larry Wall  : John K. Ousterhout : CTSS : Multix OS Unix History : Unix shell history : VI editor : History of pipes concept : Solaris : MS DOSProgramming Languages History : PL/1 : Simula 67 : C : History of GCC developmentScripting Languages : Perl history   : OS History : Mail : DNS : SSH : CPU Instruction Sets : SPARC systems 1987-2006 : Norton Commander : Norton Utilities : Norton Ghost : Frontpage history : Malware Defense History : GNU Screen : OSS early history

Classic books:

The Peter Principle : Parkinson Law : 1984 : The Mythical Man-MonthHow to Solve It by George Polya : The Art of Computer Programming : The Elements of Programming Style : The Unix Hater’s Handbook : The Jargon file : The True Believer : Programming Pearls : The Good Soldier Svejk : The Power Elite

Most popular humor pages:

Manifest of the Softpanorama IT Slacker Society : Ten Commandments of the IT Slackers Society : Computer Humor Collection : BSD Logo Story : The Cuckoo's Egg : IT Slang : C++ Humor : ARE YOU A BBS ADDICT? : The Perl Purity Test : Object oriented programmers of all nations : Financial Humor : Financial Humor Bulletin, 2008 : Financial Humor Bulletin, 2010 : The Most Comprehensive Collection of Editor-related Humor : Programming Language Humor : Goldman Sachs related humor : Greenspan humor : C Humor : Scripting Humor : Real Programmers Humor : Web Humor : GPL-related Humor : OFM Humor : Politically Incorrect Humor : IDS Humor : "Linux Sucks" Humor : Russian Musical Humor : Best Russian Programmer Humor : Microsoft plans to buy Catholic Church : Richard Stallman Related Humor : Admin Humor : Perl-related Humor : Linus Torvalds Related humor : PseudoScience Related Humor : Networking Humor : Shell Humor : Financial Humor Bulletin, 2011 : Financial Humor Bulletin, 2012 : Financial Humor Bulletin, 2013 : Java Humor : Software Engineering Humor : Sun Solaris Related Humor : Education Humor : IBM Humor : Assembler-related Humor : VIM Humor : Computer Viruses Humor : Bright tomorrow is rescheduled to a day after tomorrow : Classic Computer Humor

The Last but not Least Technology is dominated by two types of people: those who understand what they do not manage and those who manage what they do not understand ~Archibald Putt. Ph.D


Copyright © 1996-2021 by Softpanorama Society. www.softpanorama.org was initially created as a service to the (now defunct) UN Sustainable Development Networking Programme (SDNP) without any remuneration. This document is an industrial compilation designed and created exclusively for educational use and is distributed under the Softpanorama Content License. Original materials copyright belong to respective owners. Quotes are made for educational purposes only in compliance with the fair use doctrine.

FAIR USE NOTICE This site contains copyrighted material the use of which has not always been specifically authorized by the copyright owner. We are making such material available to advance understanding of computer science, IT technology, economic, scientific, and social issues. We believe this constitutes a 'fair use' of any such copyrighted material as provided by section 107 of the US Copyright Law according to which such material can be distributed without profit exclusively for research and educational purposes.

This is a Spartan WHYFF (We Help You For Free) site written by people for whom English is not a native language. Grammar and spelling errors should be expected. The site contain some broken links as it develops like a living tree...

You can use PayPal to to buy a cup of coffee for authors of this site

Disclaimer:

The statements, views and opinions presented on this web page are those of the author (or referenced source) and are not endorsed by, nor do they necessarily reflect, the opinions of the Softpanorama society. We do not warrant the correctness of the information provided or its fitness for any purpose. The site uses AdSense so you need to be aware of Google privacy policy. You you do not want to be tracked by Google please disable Javascript for this site. This site is perfectly usable without Javascript.

Last modified: March, 12, 2019