(6.1.2013, keywords: bash, lftp, script, ftp, transfer, mirror)
lftp is a file transfer program which has a rsync type options for transferring files to remote sites when rsync is not available. mirror2ftp is a command line shell (a bash script) which is meant to simplify (somewhat) the use of lftp program especially for ftp servers.
If you are familiar with graphical tools, you might be better off using tools like FileZilla, gftp or similar.
user@teac:~/Downloads$ sudo cp mirror2ftp.sh \
/usr/local/bin/mirror2ftp
[sudo] password for user: [your-passwd-here]
user@teac:~/Downloads$ sudo chmod ugo+x /usr/local/bin/mirror2ftp
user@teac:~/Downloads$ ls -l /usr/local/bin
total 28
:
-rwxr-xr-x. 1 root root 5426 May 19 2013 mirror2ftp
:
user@teac:~/Downloads$ mirror2ftp -h
Usage:
mirror2ftp [-u|--username] username] [[-p|--password] password]
[-d|--delete] [-v|--verbose]
[[-s|--source] local-directory]
[[-f|--ftp] ftp-server-name]
[[-t|--target] site-directory]
Arguments are:
[-u|--username [username]
account name for ftp site
[-p|--password password]
password for account
[[-s|--source] local-directory]
local directory from which to mirror (a source)
[[-f|--ftp ftp-server-name]
target ftp site (DNS) name or IP address
[[-t|--target site-directory]
target ftp site directory
[-d|--delete]
delete target files which do not exist in source (not default)
[-h|--help]
show these instructions
[-v|--verbose]
show more detailed outputYou can for example update web pages in server which only allow ftp (such still exists...). You can do this with graphical clients quite well, but with this you transfer only changed files which makes transfer faster.
Example. (backslash means that next line belongs to previous one)
user@teac:~/www$ mirror2ftp -v -d -u [your-username-here] \
-p [your-passwd-here] \
-s /home/www/domainname/html/ \
-f ftp.domainname.com \
-t public_html/
If you forget to give some essential argument, script starts in interactive mode.
If you leave out delete option (-d), files accumulate in targed end.
Note that target directory is at the same level as the source directory. So example above is copying directory ...domainname/html/ contents to a (relative) directory public_html/. Directory html is not copied under directory public_html.
Also note that while you can use relative URLs (like the target directory in example) you might have to write whole URL. Make first a trial run with small amount of files; especially delete option -d might cause some unpleasant suprises. You might also consider full backup before trying delete option.
Version 0.1 (18.5.2013)
As file: mirror2ftp.sh
Powered by CMSimple_XH | RO