Published on: May 22, 2010 by George K.
In website migration services, we often need to migrate websites using LFTP. Let us see what is mean by LFTP and how this can be used to migrate websites.
LFTP – (Leech File Transfer Protocol or is it Lukyanov File Transfer Protocol ? ) is a very powerful shell-like command line ftp client. Besides FTP, it also supports FTPS, HTTP, HTTPS, HFTP, FISH, and SFTP by specifying the desired protocol in a location URL. One feature which is especially handy is support for FXP i.e. data transfers between two FTP servers, bypassing the client machine. It even support torrent protocol. Cool isn’t it ?
Every operation in lftp is reliable, that is any non fatal error is ignored and the operation is repeated. So if downloading breaks, it will be restarted from the point automatically. lftp will try to retrieve the file from the very beginning until the file is transferred completely.
You can install lftp using any of the common methods like yum, apt-get or rpm. If you are a geek, likes to compile from source and prefer latest versions , then you should get it from http://lftp.yar.ru/get.html
Establishing connection to the server / site is quite simple as in the case of ftp.
For anonymous connections,
#lftp ftpsite Eg : lftp 192.168.1.52 lftp 192.168.1.52:~>
here you will get the exact prompt as of lftp and you may feel that you logged into the server without providing any login info . But lftp isn’t actually connected to the server. There’s no need to connect until you actually send a request. Suppose if I try to send request to the server using the command ‘ls’ , then only the lftp try to connect to the server.
The syntax for LFTP is
lftp -u username,password -p [portno] ftpsite
If FTP runs on default port you can omit the switch “p”
lftp has built-in 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 format of the command is
mirror path/to/source_directory path/to/target_directory
Or you can use the following format without login to the server.
lftp -u username ,password -e "mirror –verbose path/to/source_directory path/to/target_directory” ftpsite
Eg: To synchronize /home/user/public_html to “backup” folder in your machine
log into the server using lftp and then execute the command
192.168.1.52:~> mirror /home/user/public_html /backup/
The mirror command has a set of switches, which can be used to control the synchronization process.
--delete – used to delete the files in the local folder that are not present in the remote directory
--only-newer — option to download only newer files
--exclude – is to specify which files and directories to skip during synchronization.
lftp stays connected and runs the specified commands if you specify the switch “-e” .
So a command with all these switches will look like the following one
lftp -u username,password -e “mirror –delete –only-newer –verbose path/to/source_directory path/to/target_directory” ftpsite
If you want to synchronize local directory to FTP server, ie upload the directory tree in your machine to the server, we can use the –reverse switch. Here the command will look like
lftp -u username,password -e “mirror –reverse –delete –only-newer –verbose path/to/source_directory path/to/target_directory” ftpsite
As the name suggests, the switch reverses the source and target directories, so lftp uploads files from the local directory to the remote FTP server.
You can use our website migration services for getting assistance on website migration.
Category : General, Howtos, Linux