Search This Blog

Website file Uploads With lftp

Keeping your website updated is tedious job,especially when you have lot of files,which you edit quite often.And having to do the such work over ftp makes it worse.

In this article we’ll use a command line based file transfer program lftp(http://lftp.yar.ru/) written by Alexander .V. Lukyanov to do website file uploads.Though
there are many other ftp clients,lftp is simpler to use,feature rich,can upload several files in parallel and it comes bundled up with most Gnu/Linux distributions.
lftp is a powerful tool, its built-in mirror facility is suitable for keeping your website updated and secure by replicating permissions on the uploaded files.It checks for modified files by checking the file sizes and file modification times.

Using lftp on Command Line

Now you have a local directory on your computer where you keep all your website files(/home/joe/site_files).Let upload these files to your remote webserver directory using lftp on command line.First lets connect to your hosting service providers webserver with username and password.

$ lftp -u username ftp.hostingcompany.net
Password:

The lftp program will prompt for the password,type your secret password and you will be logged in.

Now issue the ‘lcd’ command to change directory to local directory where your all website files reside.

Save all the commands in a file ‘upload_mysite’ and make it executable with ‘chmod +x upload_mysite’.Run the script by typing ‘./upload_mysite’ on the command line.As your username and password are stored it file,its a better not let anyone else to view it.Changing file permissions with ‘chmod go-rwx upload_mysite’.

Maintaining Multiple Websites

Running lftp from script is not a good idea if you have to maintain multiple sites.Instead you can use lftp’s ‘-f’ option.You can store settings of different websites into separate files.Suppose you have two websites site1 and site2.

The settings of the both the sites are stored in files ‘mysite1.lftp’ and ‘mysite2.lftp.

Some other usefull features provided by ‘mirror’ built-in are the —parallel = N where in it will use N simultaneous connections to upload the files,this speeds up the upload considerably.If you want to exclude some files from being uploaded use (- x , – X) . And —delete to remove those files which are not present in local directory.

lftp can also be run as a cron job . Jani Reinikainen shows an interesting use of lftp to periodically mirroring a directory to a remote computer.