ftpsync - Sync a hierarchy of local files with a remote FTP repository
ftpsync [-h] [-c] [-v] [-d] [-k] [-P] [-s server] [-u username] [-p password] [-r remote] [-l local] [-i ignore] [-I ignore] [-o offset] [-R src=dst,src=dst... ]
The recognized flags are described below:
Net::FTPobject in debug mode and also emit some debugging information about what's being done.
Set passive mode.
-I ignoreis given, also local files matching this regexp will be left alone.
Several source / destinations pairs may be given an should be separated by a comma.
If there are local files foo/a and bar/a, giving the option
specifies to copy the local foo/a to the remote file foo/b
as well as bar/a is copied to the remote file bar/b.
If you want only foo/a to be renamed, use: -Rfoo/a=foo/b.
This may be used e.g. to copy a .htaccess file from the local site, where it's ``disabled'' (by naming it htaccess, i.e. without the leading dot on the local site) and ``enable'' it by copying it as .htaccess to the remote site. Doing so, your local copy of the web pages may be seen without any access restriction, while on the remote site, the user must provide a password (see the specifications of .htaccess of your web server).
This is an example script that should be usable as is for simple website maintenance. It synchronizes a hierarchy of local files / directories with a subtree of an FTP server.
The synchronyzation is quite simplistic (it uses time stamps and
file size comparision). It was written to explain how
use Net::FTP and
Always use the
-k option before using it in production, to avoid
ftpsync -c -s my.ftp -u lem -p 37337 \ -l /my/local/site -i '\bRCS\b|\bCVS\b|(^\.)|/\.|(~$)' -v -o 14400 \ -R htaccess=.htaccess,htpasswd=.htpasswd
The regexp I feed to -i should prevent any CVS control files, which begins with a dot, as well as all RCS files, and any Emacs backups from being touched at all. I also specify an offset of 14,400 seconds (4 hours) to compensate for the fact that this FTP server is running in my local time zone instead of in UTC, as it should be. The -R flag specifies that htaccess files are copied as files .htaccess
The synchronization is not quite complete. This script does not deal with symbolic links. Many cases are not handled to keep the code short and understandable.
Perl(1) and the perl modules
The original script was written by Luis E. Muñoz <firstname.lastname@example.org>
It was extended by Dr. Jürgen Vollmer <email@example.com>, who added
- the -R switch (rename) - the -I switch and modified -i - the -c switch - a check for file-sizes
Homepage of the original version of ftpsync:
Homepage of this version of ftpsync:
If you find this software useful, I (Juergen Vollmer) would be glad to receive a postcard from you, showing the place where you're living:
Dr. Juergen Vollmer, Viktoriastrasse 15, D-76133 Karlsruhe, Germany.
This code can be used under the same terms as Perl itself. It comes with absolutely NO WARRANTY.
Use at your own risk.
2.0 of 2005/01/25
Perl(1).Dr. Jürgen Vollmer (www.informatik-vollmer.de)