summaryrefslogtreecommitdiffstats
path: root/emacs.d/nxhtml/nxhtml/html-upl
diff options
context:
space:
mode:
Diffstat (limited to 'emacs.d/nxhtml/nxhtml/html-upl')
-rw-r--r--emacs.d/nxhtml/nxhtml/html-upl/COPYING340
-rw-r--r--emacs.d/nxhtml/nxhtml/html-upl/Changes115
-rw-r--r--emacs.d/nxhtml/nxhtml/html-upl/README111
-rw-r--r--emacs.d/nxhtml/nxhtml/html-upl/TODO2
-rw-r--r--emacs.d/nxhtml/nxhtml/html-upl/ftpsync.pl700
5 files changed, 1268 insertions, 0 deletions
diff --git a/emacs.d/nxhtml/nxhtml/html-upl/COPYING b/emacs.d/nxhtml/nxhtml/html-upl/COPYING
new file mode 100644
index 0000000..5b6e7c6
--- /dev/null
+++ b/emacs.d/nxhtml/nxhtml/html-upl/COPYING
@@ -0,0 +1,340 @@
+ GNU GENERAL PUBLIC LICENSE
+ Version 2, June 1991
+
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.
+ 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+ Preamble
+
+ The licenses for most software are designed to take away your
+freedom to share and change it. By contrast, the GNU General Public
+License is intended to guarantee your freedom to share and change free
+software--to make sure the software is free for all its users. This
+General Public License applies to most of the Free Software
+Foundation's software and to any other program whose authors commit to
+using it. (Some other Free Software Foundation software is covered by
+the GNU Library General Public License instead.) You can apply it to
+your programs, too.
+
+ When we speak of free software, we are referring to freedom, not
+price. Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+this service if you wish), that you receive source code or can get it
+if you want it, that you can change the software or use pieces of it
+in new free programs; and that you know you can do these things.
+
+ To protect your rights, we need to make restrictions that forbid
+anyone to deny you these rights or to ask you to surrender the rights.
+These restrictions translate to certain responsibilities for you if you
+distribute copies of the software, or if you modify it.
+
+ For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must give the recipients all the rights that
+you have. You must make sure that they, too, receive or can get the
+source code. And you must show them these terms so they know their
+rights.
+
+ We protect your rights with two steps: (1) copyright the software, and
+(2) offer you this license which gives you legal permission to copy,
+distribute and/or modify the software.
+
+ Also, for each author's protection and ours, we want to make certain
+that everyone understands that there is no warranty for this free
+software. If the software is modified by someone else and passed on, we
+want its recipients to know that what they have is not the original, so
+that any problems introduced by others will not reflect on the original
+authors' reputations.
+
+ Finally, any free program is threatened constantly by software
+patents. We wish to avoid the danger that redistributors of a free
+program will individually obtain patent licenses, in effect making the
+program proprietary. To prevent this, we have made it clear that any
+patent must be licensed for everyone's free use or not licensed at all.
+
+ The precise terms and conditions for copying, distribution and
+modification follow.
+
+ GNU GENERAL PUBLIC LICENSE
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+ 0. This License applies to any program or other work which contains
+a notice placed by the copyright holder saying it may be distributed
+under the terms of this General Public License. The "Program", below,
+refers to any such program or work, and a "work based on the Program"
+means either the Program or any derivative work under copyright law:
+that is to say, a work containing the Program or a portion of it,
+either verbatim or with modifications and/or translated into another
+language. (Hereinafter, translation is included without limitation in
+the term "modification".) Each licensee is addressed as "you".
+
+Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope. The act of
+running the Program is not restricted, and the output from the Program
+is covered only if its contents constitute a work based on the
+Program (independent of having been made by running the Program).
+Whether that is true depends on what the Program does.
+
+ 1. You may copy and distribute verbatim copies of the Program's
+source code as you receive it, in any medium, provided that you
+conspicuously and appropriately publish on each copy an appropriate
+copyright notice and disclaimer of warranty; keep intact all the
+notices that refer to this License and to the absence of any warranty;
+and give any other recipients of the Program a copy of this License
+along with the Program.
+
+You may charge a fee for the physical act of transferring a copy, and
+you may at your option offer warranty protection in exchange for a fee.
+
+ 2. You may modify your copy or copies of the Program or any portion
+of it, thus forming a work based on the Program, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+ a) You must cause the modified files to carry prominent notices
+ stating that you changed the files and the date of any change.
+
+ b) You must cause any work that you distribute or publish, that in
+ whole or in part contains or is derived from the Program or any
+ part thereof, to be licensed as a whole at no charge to all third
+ parties under the terms of this License.
+
+ c) If the modified program normally reads commands interactively
+ when run, you must cause it, when started running for such
+ interactive use in the most ordinary way, to print or display an
+ announcement including an appropriate copyright notice and a
+ notice that there is no warranty (or else, saying that you provide
+ a warranty) and that users may redistribute the program under
+ these conditions, and telling the user how to view a copy of this
+ License. (Exception: if the Program itself is interactive but
+ does not normally print such an announcement, your work based on
+ the Program is not required to print an announcement.)
+
+These requirements apply to the modified work as a whole. If
+identifiable sections of that work are not derived from the Program,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works. But when you
+distribute the same sections as part of a whole which is a work based
+on the Program, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Program.
+
+In addition, mere aggregation of another work not based on the Program
+with the Program (or with a work based on the Program) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+ 3. You may copy and distribute the Program (or a work based on it,
+under Section 2) in object code or executable form under the terms of
+Sections 1 and 2 above provided that you also do one of the following:
+
+ a) Accompany it with the complete corresponding machine-readable
+ source code, which must be distributed under the terms of Sections
+ 1 and 2 above on a medium customarily used for software interchange; or,
+
+ b) Accompany it with a written offer, valid for at least three
+ years, to give any third party, for a charge no more than your
+ cost of physically performing source distribution, a complete
+ machine-readable copy of the corresponding source code, to be
+ distributed under the terms of Sections 1 and 2 above on a medium
+ customarily used for software interchange; or,
+
+ c) Accompany it with the information you received as to the offer
+ to distribute corresponding source code. (This alternative is
+ allowed only for noncommercial distribution and only if you
+ received the program in object code or executable form with such
+ an offer, in accord with Subsection b above.)
+
+The source code for a work means the preferred form of the work for
+making modifications to it. For an executable work, complete source
+code means all the source code for all modules it contains, plus any
+associated interface definition files, plus the scripts used to
+control compilation and installation of the executable. However, as a
+special exception, the source code distributed need not include
+anything that is normally distributed (in either source or binary
+form) with the major components (compiler, kernel, and so on) of the
+operating system on which the executable runs, unless that component
+itself accompanies the executable.
+
+If distribution of executable or object code is made by offering
+access to copy from a designated place, then offering equivalent
+access to copy the source code from the same place counts as
+distribution of the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+ 4. You may not copy, modify, sublicense, or distribute the Program
+except as expressly provided under this License. Any attempt
+otherwise to copy, modify, sublicense or distribute the Program is
+void, and will automatically terminate your rights under this License.
+However, parties who have received copies, or rights, from you under
+this License will not have their licenses terminated so long as such
+parties remain in full compliance.
+
+ 5. You are not required to accept this License, since you have not
+signed it. However, nothing else grants you permission to modify or
+distribute the Program or its derivative works. These actions are
+prohibited by law if you do not accept this License. Therefore, by
+modifying or distributing the Program (or any work based on the
+Program), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Program or works based on it.
+
+ 6. Each time you redistribute the Program (or any work based on the
+Program), the recipient automatically receives a license from the
+original licensor to copy, distribute or modify the Program subject to
+these terms and conditions. You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties to
+this License.
+
+ 7. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Program at all. For example, if a patent
+license would not permit royalty-free redistribution of the Program by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Program.
+
+If any portion of this section is held invalid or unenforceable under
+any particular circumstance, the balance of the section is intended to
+apply and the section as a whole is intended to apply in other
+circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system, which is
+implemented by public license practices. Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+ 8. If the distribution and/or use of the Program is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Program under this License
+may add an explicit geographical distribution limitation excluding
+those countries, so that distribution is permitted only in or among
+countries not thus excluded. In such case, this License incorporates
+the limitation as if written in the body of this License.
+
+ 9. The Free Software Foundation may publish revised and/or new versions
+of the General Public License from time to time. Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+Each version is given a distinguishing version number. If the Program
+specifies a version number of this License which applies to it and "any
+later version", you have the option of following the terms and conditions
+either of that version or of any later version published by the Free
+Software Foundation. If the Program does not specify a version number of
+this License, you may choose any version ever published by the Free Software
+Foundation.
+
+ 10. If you wish to incorporate parts of the Program into other free
+programs whose distribution conditions are different, write to the author
+to ask for permission. For software which is copyrighted by the Free
+Software Foundation, write to the Free Software Foundation; we sometimes
+make exceptions for this. Our decision will be guided by the two goals
+of preserving the free status of all derivatives of our free software and
+of promoting the sharing and reuse of software generally.
+
+ NO WARRANTY
+
+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
+FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
+OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
+PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
+OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
+TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
+PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
+REPAIR OR CORRECTION.
+
+ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
+REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
+INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
+OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
+TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
+YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
+PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGES.
+
+ END OF TERMS AND CONDITIONS
+
+ How to Apply These Terms to Your New Programs
+
+ If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+ To do so, attach the following notices to the program. It is safest
+to attach them to the start of each source file to most effectively
+convey the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+ <one line to give the program's name and a brief idea of what it does.>
+ Copyright (C) <year> <name of author>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+
+Also add information on how to contact you by electronic and paper mail.
+
+If the program is interactive, make it output a short notice like this
+when it starts in an interactive mode:
+
+ Gnomovision version 69, Copyright (C) year name of author
+ Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+ This is free software, and you are welcome to redistribute it
+ under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License. Of course, the commands you use may
+be called something other than `show w' and `show c'; they could even be
+mouse-clicks or menu items--whatever suits your program.
+
+You should also get your employer (if you work as a programmer) or your
+school, if any, to sign a "copyright disclaimer" for the program, if
+necessary. Here is a sample; alter the names:
+
+ Yoyodyne, Inc., hereby disclaims all copyright interest in the program
+ `Gnomovision' (which makes passes at compilers) written by James Hacker.
+
+ <signature of Ty Coon>, 1 April 1989
+ Ty Coon, President of Vice
+
+This General Public License does not permit incorporating your program into
+proprietary programs. If your program is a subroutine library, you may
+consider it more useful to permit linking proprietary applications with the
+library. If this is what you want to do, use the GNU Library General
+Public License instead of this License.
diff --git a/emacs.d/nxhtml/nxhtml/html-upl/Changes b/emacs.d/nxhtml/nxhtml/html-upl/Changes
new file mode 100644
index 0000000..0bfd93c
--- /dev/null
+++ b/emacs.d/nxhtml/nxhtml/html-upl/Changes
@@ -0,0 +1,115 @@
+
+1.26 => 1.27 (2004-08-23)
+=========================
+
+ * Proposed and partially provided by Samuel Marshall <sam@leafdigital.com>
+ * enhanced timezone handling, should be perfect now
+ * new option -c, like -i but then asks interactively to let do it
+ * if FTP user/password are set to ?, they are asked for interactively
+
+
+1.25 => 1.26 (2004-03-31)
+=========================
+
+ * fixed "dangerous" algorithm of synchronization direction
+
+
+1.24 => 1.25 (2004-03-20)
+=========================
+
+ * fixed some 1.24 bugs
+ * clock offset computation now more resistant against very slow connections
+ * clock offset computation disabled for GET mode, so mirroring of foreign
+ stuff is now possible again
+ * default localdir of . disabled, therefore
+ * using . as localdir parameter does not cause a parsing error any more
+ * replaced damn indentation tabs in sourcecode by appropriate number of
+ spaces, so code is readable independent of tab settings
+ * enabled handling of ftpdir /
+ * handling of relative ftpdir corrected
+
+
+1.23 => 1.24 (2003-10-11)
+=========================
+
+ By Michiel Steltman <Msteltman@disway.nl>
+
+ * handle files with blanks etc in names
+ * clock offset remote-local to reduce unnecessary transfers
+ * error handling
+
+
+1.22 => 1.23 (2003-09-28)
+=========================
+
+ * New parameter timeout
+
+
+1.21 => 1.22 (2003-03-24)
+=========================
+
+ * Now cuts of / at directory spec's end, to avoid pwd() being different
+ from target of cwd() (which lead to unneccesarry abortions)
+
+
+1.20 => 1.21 (2003-03-24)
+=========================
+
+ * version information in sourcefile and output of -h command
+
+
+1.11 => 1.20 (2003-03-22)
+=========================
+
+ * generally, most foreseeable problems are beeing checked, in particular:
+
+ - unability to connect to FTP server
+ - unability to login into FTP server
+ - unability to change to local or remote base directory
+ - unability to change to remote subdirectory
+ - unability to create local or remote subdirectory
+ - unability to remove local or remote subdirectory
+ - unability to put or get a file within 3 trials
+
+ All these errors (except the last one) leads to immediate abortion.
+
+
+1.10 => 1.11 (2002-05-10)
+=========================
+
+ * Some optical corrections concerning output
+
+ * Files are now automatically re-transferred until the size on both ends
+ matches
+
+ * -? now corrrectly recognized
+
+
+1.00 => 1.10 (2001-10-28)
+=========================
+
+ * config file support
+ This is mportant to avoid putting ftp passwords in the process list!
+
+ * much more informative standard and verbose/debug output, including kind
+ of a advance information
+
+ * better FTP-URL parsing supporting such without user/password
+
+ * much better default values, e.g. ftp://ftp:anonymous@localhost/., ...
+
+ * softlinks are now detected (locally and remote) and treated somewhat
+ correctly, i.e. they are ignored correctly ;-))
+
+
+
+=> 1.00 (2001-10-26)
+====================
+
+* 1.0 created 2001-10-20 23:10 by Christoph Lechleitner <lech@ibcl.at>
+
+Quite good for a 5 hour hack, isn't it?
+O.K., I have already written similar programs for local file systems
+in Pascal for DOS, Win3x and OS/2, and in VisualBasic for Win95b.
+
+
diff --git a/emacs.d/nxhtml/nxhtml/html-upl/README b/emacs.d/nxhtml/nxhtml/html-upl/README
new file mode 100644
index 0000000..3f9f505
--- /dev/null
+++ b/emacs.d/nxhtml/nxhtml/html-upl/README
@@ -0,0 +1,111 @@
+# README file for ftpsync.pl
+
+
+Contents:
+=========
+
+- Overview
+- Why use ftpsync.pl instead of mirror, sitecopy, ...?
+- Requirements/Restrictions
+- Bug reports, Contact
+- License
+- Updates
+
+
+Overview:
+---------
+
+ftpsync.pl synchronizes a local directory tree and a remote FTP directory tree.
+
+It was initally written to automize web publishing, but might be useful for
+some other purposes, like mirroring not-too-large public sites, data
+replication, and more.
+
+Call "ftpsync.pl -h" to get a short parameter explanation.
+
+
+Why use ftpsync.pl instead of mirror, sitecopy, ...?
+----------------------------------------------------
+
+Yes, there are similar projects, so some comments on them:
+
+Compared to mirror, ftpsync.pl is capable of PUTing, not only GETing stuff
+(Don't blame me if mirror is able to PUT, I could'nt find a way).
+
+Compared to sitecopy, ftpsync.pl has no problems, if the remote site has been
+changed since its last run by other tools and activites. Unless network
+problems or bugs occur, ftpsync.pl does a reliable synchronization.
+
+Compared to both, ftpsync.pl is very lightweight ;-))
+
+
+Requirements / Restrictions:
+----------------------------
+
+- Perl 5.6+
+ ftpsync.pl was initially developed on Perl 5.6.0-81 on SuSE Linux 7.2,
+ older Perl 5.x version might work. Test reports welcome at ftpsync@ibcl.at!
+
+- File::Find, IO::Handle
+ IMHO parts of the basic perl package.
+
+- Net::FTP
+ Part of the perl-libnet package.
+
+- UNIX like operating systems on local system
+ Porting to DOS based systems should be easily done by changing the
+ directory separator.
+
+- Perhaps, the script does not work with all FTP servers
+ It is beeing tested only against UNIX based FTP servers.
+
+
+Bug-Reports, Contact:
+---------------------
+
+Besides ftpsync.sourceforge.net, ftpsync@ibcl.at is a good target for comments
+of any kind.
+
+
+License:
+--------
+
+FTPSync.pl is GNU/GPL software and eMail ware.
+
+
+FTPSync.pl as GNU/GPL software:
+-------------------------------
+
+FTPSync.pl (ftpsync.pl) is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+See attached file COPYING.
+
+
+FTPSync.pl as eMail ware:
+-------------------------
+
+FTPSync.pl is also eMail-Ware, which means that the initial author
+(Christoph Lechleitner) would like to get an eMail (to ftpsync@ibcl.at),
+- if anyone uses the script on production level,
+- if anyone distributes or advertises it in any way,
+- if anyone starts to (try to) improve it.
+
+
+Updates
+-------
+
+The software and updates should be available from
+http://ftpsync.sourceforge.net/
+http://www.ibcl.at/ossw/FTPSync
diff --git a/emacs.d/nxhtml/nxhtml/html-upl/TODO b/emacs.d/nxhtml/nxhtml/html-upl/TODO
new file mode 100644
index 0000000..923583d
--- /dev/null
+++ b/emacs.d/nxhtml/nxhtml/html-upl/TODO
@@ -0,0 +1,2 @@
+
+Nothing as of now.
diff --git a/emacs.d/nxhtml/nxhtml/html-upl/ftpsync.pl b/emacs.d/nxhtml/nxhtml/html-upl/ftpsync.pl
new file mode 100644
index 0000000..729d964
--- /dev/null
+++ b/emacs.d/nxhtml/nxhtml/html-upl/ftpsync.pl
@@ -0,0 +1,700 @@
+#!/usr/bin/perl
+#
+# ftpsync.pl
+#
+# See attached README file for any details, or call
+# ftpsync.pl -h
+# for quick start.
+#
+# LICENSE
+#
+# FTPSync.pl (ftpsync) is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+# FTPSync.pl (ftpsync) is also eMail-Ware, which means that the initial author
+# (Christoph Lechleitner) would like to get an eMail at ftpsync@ibcl.at, if
+# - if anyone uses the script on production level,
+# - if anyone distributes or advertises it in any way,
+# - if anyone starts to (try to) improve it.
+#
+#
+################################################################################
+
+#
+# Options etc.
+#
+#print "Starting imports.\n"; # For major problem debugging
+printf STDERR "argv=@ARGV\n";
+
+use File::Find;
+use File::Listing;
+use Net::FTP;
+use strict;
+# flushing ...
+use IO::Handle;
+STDOUT->autoflush(1);
+STDERR->autoflush(1);
+
+sub dosync();
+sub print_syntax();
+sub print_options();
+sub buildremotetree();
+sub buildlocaltree();
+sub listremotedirs();
+sub parseRemoteURL();
+
+# Option Variables
+#print "Defining variables.\n"; # For major problem debugging
+# meta
+my $returncode=0;
+my $configfile=$ENV{"HOME"}."/.ftpsync";
+# basics
+my $localdir="";
+my $remoteURL="";
+my $syncdirection="";
+my $ftpuser="ftp";
+my $ftppasswd="anonymous";
+my $ftpserver="localhost";
+my $ftpdir="";
+my $ftptimeout=120;
+my $syncoff=0;
+# verbosity
+my $doverbose=1;
+my $dodebug=0;
+my $doquiet=0;
+my $doinfoonly=0;
+my $infotext="";
+my $docheckfirst=0;
+
+# Read command line options/parameters
+#print "Reading command line options.\n"; # For major problem debugging
+my $curopt;
+my @cloptions=();
+for $curopt (@ARGV) {
+ if ($curopt =~ /^cfg=/) {
+ $configfile=$';
+ if (! -r $configfile) { print "Config file does not exist: ".$configfile."\n"; $returncode+=1; }
+ } else {
+ push @cloptions, $curopt;
+ }
+}
+
+# Read Config File, if given
+my @cfgfoptions=();
+if ($configfile ne "") {
+ if (-r $configfile) {
+ #print "Reading config file.\n"; # For major problem debugging
+ open (CONFIGFILE,"<$configfile");
+ while (<CONFIGFILE>) {
+ $_ =~ s/([ \n\r]*$|\.\.|#.*$)//gs;
+ if ($_ eq "") { next; }
+ if ( ($_ =~ /[^=]+=[^=]+/) || ($_ =~ /^-[a-zA-Z]+$/) ) { push @cfgfoptions, $_; }
+ }
+ close (CONFIGFILE);
+ } # else { print "Config file does not exist.\n"; } # For major problem debugging
+} # else { print "No config file to read.\n"; } # For major problem debugging
+
+# Parse Options/Parameters
+print "Parsing all options.\n"; # For major problem debugging
+my $noofopts=0;
+for $curopt (@cfgfoptions, @cloptions) {
+ if ($curopt =~ /^-[a-zA-Z]/) {
+ my $i;
+ for ($i=1; $i<length($curopt); $i++) {
+ my $curoptchar=substr($curopt,$i,1);
+ $noofopts++;
+ if ($curoptchar =~ /[cC]/) { $docheckfirst=1; }
+ elsif ($curoptchar =~ /[dD]/) { $dodebug=1; $doverbose=1; $doquiet=0; }
+ elsif ($curoptchar =~ /[gG]/) { $syncdirection="get"; }
+ elsif ($curoptchar =~ /[hH?]/) { print_syntax(); exit 0; }
+ elsif ($curoptchar =~ /[iI]/) { $doinfoonly=1; }
+ elsif ($curoptchar =~ /[pP]/) { $syncdirection="put"; }
+ elsif ($curoptchar =~ /[qQ]/) { $dodebug=0; $doverbose=0; $doquiet=1; }
+ elsif ($curoptchar =~ /[vV]/) { $doverbose++; }
+ else { print "ERROR: Unknown option: \"-".$curoptchar."\"\n"; $returncode+=1; }
+ }
+ }
+ elsif ($curopt =~ /^ftp:\/\/(([^@\/\\\:]+)(:([^@\/\\\:]+))?@)?([a-zA-Z01-9\.]+)\/(.*)/) {
+ $remoteURL = $curopt;
+ parseRemoteURL();
+ if ( $syncdirection eq "" )
+ { $syncdirection="get"; }
+ }
+ elsif ($curopt =~ /^[a-z]+=.+/) {
+ my ($fname, $fvalue) = split /=/, $curopt, 2;
+ if ($fname eq "cfg") { next; }
+ elsif ($fname eq "ftpdir") { $ftpdir =$fvalue;
+ if ($ftpdir ne "/") { $ftpdir=~s/\/$//; }
+ if ( $syncdirection eq "" ) { $syncdirection="get"; }
+ }
+ elsif ($fname =~ m/ftppass(w(or)?d)?/i)
+ { $ftppasswd=$fvalue;
+ if ( $syncdirection eq "" ) { $syncdirection="get"; }
+ }
+ elsif ($fname eq "ftpserver") { $ftpserver =$fvalue;
+ if ( $syncdirection eq "" ) { $syncdirection="get"; }
+ }
+ elsif ($fname eq "ftpuser") { $ftpuser =$fvalue;
+ if ( $syncdirection eq "" ) { $syncdirection="get"; }
+ }
+ elsif ($fname eq "localdir") { $localdir =$fvalue; $localdir=~s/\/$//;
+ if ( $syncdirection eq "" ) { $syncdirection="put"; }
+ }
+ elsif ($fname eq "timeout") { if ($fvalue>0) { $ftptimeout =$fvalue; } }
+ }
+ else {
+ if ($localdir eq "") {
+ $localdir = $curopt;
+ if ( $syncdirection eq "" )
+ { $syncdirection="put"; }
+ } else {
+ print "ERROR: Unknown parameter: \"".$curopt."\"\n"; $returncode+=1
+ }
+ }
+}
+if ($noofopts == 0) { print_syntax(); exit 0; }
+
+if($ftpuser eq "?") { print "User: "; $ftpuser=<STDIN>; chomp($ftpuser); }
+if($ftppasswd eq "?") { print "Password: "; $ftppasswd=<STDIN>; chomp($ftppasswd); }
+
+if ($dodebug) { print_options(); }
+# check options
+if ( ($localdir eq "") || (! -d $localdir) )
+{ print "ERROR: Local directory does not exist: ".$localdir."\n"; $returncode+=1; }
+#if ($localdir eq "") { print "ERROR: No localdir given.\n"; $returncode+=1; }
+#if ( ($remoteURL eq "") { print "ERROR: No remoteURL given.\n"; $returncode+=1; }
+if ($ftpserver eq "") { print "ERROR: No FTP server given.\n"; $returncode+=1; }
+if ($ftpdir eq "") { print "ERROR: No FTP directory given.\n"; $returncode+=1; }
+if ($ftpuser eq "") { print "ERROR: No FTP user given.\n"; $returncode+=1; }
+if ($ftppasswd eq "") { print "ERROR: No FTP password given.\n"; $returncode+=1; }
+if ($returncode > 0) { die "Aborting due to missing or wrong options! Call ftpsync -? for more information.\n"; }
+
+
+#print "Exiting.\n"; exit 0;
+
+if ($dodebug) { print "\nFind out if ftp server is online & accessible.\n"; }
+my $doftpdebug=($doverbose > 2);
+my $ftpc = Net::FTP->new($ftpserver,Debug=>$doftpdebug,Timeout=>$ftptimeout) || die "Could not connect to $ftpserver\n";
+if ($dodebug) { print "Logging in as $ftpuser with password $ftppasswd.\n" }
+$ftpc->login($ftpuser,$ftppasswd) || die "Could not login to $ftpserver as $ftpuser\n";
+my $ftpdefdir=$ftpc->pwd();
+if ($dodebug) { print "Remote directory is now ".$ftpdefdir."\n"; }
+if ($ftpdir !~ /^\//) # insert remote login directory into relative ftpdir specification
+{ if ($ftpdefdir eq "/")
+ { $ftpdir = $ftpdefdir . $ftpdir; }
+ else
+ { $ftpdir = $ftpdefdir . "/" . $ftpdir; }
+ if (!$doquiet)
+ { print "Absolute remote directory is $ftpdir\n"; }
+}
+if (substr($ftpdir, -1) eq "/") {
+ if (!$doquiet)
+ { print " Remote directory ends in /, removing this\n"; }
+ chop($ftpdir);
+}
+if ($dodebug) { print "Changing to remote directory $ftpdir.\n" }
+$ftpc->binary()
+ or die "Cannot set binary mode :\n\t" . $ftpc->message;
+$ftpc->cwd($ftpdir)
+ or die "Cannot cwd to $ftpdir :\n\t" . $ftpc->message;
+if ($ftpc->pwd() ne $ftpdir) {
+ my $pwd = $ftpc->pwd();
+ die "Could not change to remote base directory $ftpdir (at $pwd)\n"; }
+if ($dodebug) { print "Remote directory is now ".$ftpc->pwd()."\n"; }
+
+if (! $doquiet) { print "\nDetermine s offset.\n"; }
+if ($syncdirection eq "put") { clocksync($ftpc,"syncfile"); }
+
+# local & remote tree vars
+#chdir $localdir;
+my $ldl=length($localdir) + 1;
+#my $ldl=length($localdir);
+my %localfiledates=();
+my %localfilesizes=();
+my %localdirs=();
+my %locallinks=();
+
+my %remotefilesizes=();
+my %remotefiledates=();
+my %remotedirs=();
+my %remotelinks=();
+my $curremotesubdir="";
+
+# Build local & remote tree
+if (! $doquiet) { print "\nBuilding local file tree.\n"; }
+buildlocaltree();
+if (! $doquiet) { print "\nBuilding remote file tree.\n"; }
+buildremotetree();
+listremotedirs();
+#if ($dodebug) { print "Quitting FTP connection.\n" }
+#$ftpc->quit();
+
+#print "Exiting.\n"; exit 0;
+
+# Work ...
+if ($doinfoonly) { $docheckfirst=0; }
+if ($docheckfirst)
+{ print "Simulating synchronization.\n";
+ $doinfoonly=1;
+ dosync();
+ $doinfoonly=0;
+ print "\nOK to really update files? (y/n) [n] ";
+ my $yn=<STDIN>;
+ if ($yn =~ /^y/i)
+ { print "OK, going to do it.\n";
+ }
+ else
+ { print "OK, exiting without actions.\n";
+ exit 1;
+ }
+}
+if ($doinfoonly) { print "\nSimulating synchronization.\n"; }
+elsif (! $doquiet) { print "\nStarting synchronization.\n"; }
+dosync();
+
+if (!$doquiet) { print "Done.\n"; }
+
+if ($dodebug) { print "Quitting FTP connection.\n" }
+$ftpc->quit();
+
+exit 0;
+
+
+
+#
+# Subs
+#
+
+sub buildlocaltree() {
+ find (\&noticelocalfile, $localdir."/");
+ sub noticelocalfile {
+ if ($ldl > length($File::Find::name)) { return; }
+ #printf "name=%s, length(name)=%d, ldl=$ldl\n", $File::Find::name, length($File::Find::name);
+ my $relfilename=substr($File::Find::name,$ldl);
+ if (length($relfilename) == 0) { return; }
+ if (-d $_) {
+ if ($dodebug) { print "Directory: ".$File::Find::name."\n"; }
+ elsif (! $doquiet) { print ":"; }
+ $localdirs{$relfilename}="$relfilename";
+ }
+ elsif (-f $_) {
+ #my @curfilestat=lstat $File::Find::name;
+ my @curfilestat=lstat $_;
+ my $curfilesize=$curfilestat[7];
+ my $curfilemdt=$curfilestat[9];
+ if ($dodebug) { print "File: ".$File::Find::name."\n";
+ print "Modified ".$curfilemdt."\nSize ".$curfilesize." bytes\n"; }
+ elsif (! $doquiet) { print "."; }
+ $localfiledates{$relfilename}=$curfilemdt;
+ $localfilesizes{$relfilename}=$curfilesize;
+ }
+ elsif (-l $_) {
+ if ($dodebug) { print "Link: ".$File::Find::name."\n"; }
+ elsif (! $doquiet) { print ","; }
+ $locallinks{$relfilename}="$relfilename";
+ } else {
+ #print "u ".$File::Find::name."\n";
+ if (! $doquiet) { print "Ignoring file of unknown type: ".$File::Find::name."\n"; }
+ }
+ #if (! ($doquiet || $dodebug)) { print "\n"; }
+ #print "File mode is ".@curfilestat[2]."\n";
+ }
+ if ($dodebug) {
+ print "Local dirs (relative to ".$localdir."/):\n";
+ my $curlocaldir="";
+ foreach $curlocaldir (keys(%localdirs))
+ { print $curlocaldir."/\n"; }
+ print "Local files (relative to ".$localdir."/):\n";
+ my $curlocalfile="";
+ foreach $curlocalfile (keys(%localfiledates))
+ { print $curlocalfile."\n"; }
+ }
+}
+
+
+sub buildremotetree() {
+ my @currecursedirs=();
+ #$ftpc->ls()
+ # or die $ftpc->message . "\nCannot ls remote dir " . $ftpc->pwd();
+ my @rfl = $ftpc->dir();
+ # or @rfl=(); # we have to survive empty remote directories !!!
+ my $currf="";
+ my $curyear = (gmtime(time))[5] + 1900;
+ my %monthtonr=();
+ $monthtonr{"Jan"}=1; $monthtonr{"Feb"}=2; $monthtonr{"Mar"}=3; $monthtonr{"Apr"}=4; $monthtonr{"May"}=5; $monthtonr{"Jun"}=6;
+ $monthtonr{"Jul"}=7; $monthtonr{"Aug"}=8; $monthtonr{"Sep"}=9; $monthtonr{"Oct"}=10; $monthtonr{"Nov"}=11; $monthtonr{"Dec"}=12;
+ if ($dodebug) { print "Remote pwd is ".$ftpc->pwd()."\nDIRing.\n"; }
+ my $curlsline;
+ foreach $curlsline (parse_dir(\@rfl)) {
+ my ($cfname,$cftype,$cfsize,$cftime,$mode)=@$curlsline;
+ #if ($dodebug) { print "Analysing remote file/dir ".$currf."\n" };
+ if ( $cftype ) {
+ if ($cfname eq ".") { next; }
+ if ($cfname eq "..") { next; }
+ if (substr($cftype,0,1) eq 'l') { # link, rest of string = linkto
+ my $curnrl;
+ if ($curremotesubdir eq "") { $curnrl = $cfname; }
+ else { $curnrl = $curremotesubdir."/".$cfname; }
+ $remotelinks{$curnrl}=$cfname;
+ if ($dodebug) { print "Link: ".$curnrl." -> ".$cfname."\n"; }
+ }
+ elsif ($cftype eq 'd') {
+ my $curnewrsd;
+ if ($curremotesubdir eq "") { $curnewrsd = $cfname; }
+ else { $curnewrsd = $curremotesubdir."/".$cfname; }
+ $remotedirs{$curnewrsd}=$curnewrsd;
+ if ($dodebug) { print "Directory: ".$curnewrsd."\n"; }
+ elsif (! $doquiet) { print ":"; }
+ push @currecursedirs, $cfname;
+ }
+ elsif ($cftype eq 'f') { #plain file
+ my $curnewrf;
+ if ($curremotesubdir eq "") { $curnewrf = $cfname; }
+ else { $curnewrf = $curremotesubdir."/".$cfname; }
+ #$remotefiledates{$curnewrf}=$cftime;
+ $remotefiledates{$curnewrf}=$ftpc->mdtm($cfname)+$syncoff;
+ if ($remotefiledates{$curnewrf} le 0) { die "Timeout detecting modification time of $curnewrf\n"; }
+ $remotefilesizes{$curnewrf}=$cfsize;
+ if ($remotefilesizes{$curnewrf} lt 0) { die "Timeout detecting size of $curnewrf\n"; }
+ if ($dodebug) { print "File: ".$curnewrf."\n"; }
+ elsif (! $doquiet) { print "."; }
+ }
+ elsif (! $doquiet) { print "Unkown file: $curlsline\n"; }
+ }
+ elsif ($dodebug) { print "Ignoring.\n"; }
+ }
+ #recurse
+ my $currecurseddir;
+ foreach $currecurseddir (@currecursedirs)
+ { my $oldcurremotesubdir;
+ $oldcurremotesubdir=$curremotesubdir;
+ if ($curremotesubdir eq "") { $curremotesubdir = $currecurseddir; }
+ else { $curremotesubdir .= "/".$currecurseddir; }
+ my $curcwddir="";
+ if ($ftpdir eq "/")
+ { $curcwddir=$ftpdir.$curremotesubdir; }
+ else
+ { $curcwddir=$ftpdir."/".$curremotesubdir; }
+ if ($dodebug) { print "Change dir: ".$curcwddir."\n"; }
+ $ftpc->cwd($curcwddir)
+ or die "Cannot cwd to $curcwddir :\n\t" . $ftpc->message ;
+ if ($ftpc->pwd() ne $curcwddir) {
+ die "Could not cwd to $curcwddir :\n\t" . $ftpc->message ; }
+ if (! $doquiet) { print "\n"; }
+ buildremotetree();
+ $ftpc->cdup();
+ $curremotesubdir = $oldcurremotesubdir;
+ }
+}
+
+
+# Synchronize clocks.
+sub clocksync {
+ my $conn = shift @_;
+ my $fn = shift @_;
+ my $fndidexist=1;
+
+ if(! -f $fn) {
+ open(SF, ">$fn") or die "Cannot create $fn for time sync option";
+ close(SF);
+ $fndidexist=0;
+ }
+ -z $fn or
+ die "File $fn for time sync must be empty.";
+ my $putsyncok=1;
+ $conn->put($fn) or $putsyncok=0;
+ if (!$putsyncok)
+ { unlink($fn); # cleanup!
+ die "Cannot send timesync file $fn";
+ }
+
+ my $now_here1 = time();
+ my $now_there = $conn->mdtm($fn) or
+ die "Cannot get write time of timesync file $fn";
+ my $now_here2 = time();
+
+ if ($now_here2 < $now_there) # remote is in the future
+ { $syncoff=($now_there - $now_here1);
+ $syncoff -= $syncoff % 60;
+ $syncoff = 0-$syncoff;
+ }
+ else
+ #if ($now_here1 > $now_there) # remote is the past # or equal
+ { $syncoff=($now_here2 - $now_there);
+ $syncoff -= $syncoff % 60;
+ }
+
+ $conn->delete($fn);
+
+ my $hrs = int(abs($syncoff)/3600);
+ my $mins = int(abs($syncoff)/60) - $hrs*60;
+ my $secs = abs($syncoff) - $hrs*3600 - $mins*60;
+ if (! $doquiet) {
+ printf("Clock sync offset: %d:%02d:%02d\n", $hrs, $mins, $secs);
+ }
+ unlink ($fn) unless $fndidexist;
+}
+
+
+sub dosync()
+{
+ chdir $localdir || die "Could not change to local base directory $localdir\n";
+ if ($syncdirection eq "put") {
+ # create dirs missing at the target
+ if ($doinfoonly) { print "\nWould create new remote directories.\n"; }
+ elsif (! $doquiet) { print "\nCreating new remote directories.\n"; }
+ my $curlocaldir;
+ foreach $curlocaldir (sort { return length($a) <=> length($b); } keys(%localdirs))
+ { if (! exists $remotedirs{$curlocaldir})
+ { if ($doinfoonly) { print $curlocaldir."\n"; next; }
+ if ($doverbose) { print $curlocaldir."\n"; }
+ elsif (! $doquiet) { print "d"; }
+ if ($ftpc->mkdir($curlocaldir) ne $curlocaldir) { die "Could not create remote subdirectory $curlocaldir\n"; }
+ }
+ }
+ # copy files missing or too old at the target, synchronize timestamp _after_ copying
+ if ($doinfoonly) { print "\nWould copy new(er) local files.\n"; }
+ elsif (! $doquiet) { print "\nCopying new(er) local files.\n"; }
+ my $curlocalfile;
+ foreach $curlocalfile (sort { return length($b) <=> length($a); } keys(%localfiledates))
+ { my $dorefresh=0;
+ if (! exists $remotefiledates{$curlocalfile}) {
+ $dorefresh=1;
+ $infotext="New: ".$curlocalfile." (".$localfilesizes{$curlocalfile}." bytes)\n";
+ if ($doinfoonly) { print $infotext; next; }
+ elsif ($doverbose) { print $infotext; }
+ elsif (! $doquiet) { print "n"; }
+ }
+ elsif ($remotefiledates{$curlocalfile} < $localfiledates{$curlocalfile}) {
+ $dorefresh=1;
+ $infotext="Newer: ".$curlocalfile." (".$localfilesizes{$curlocalfile}." bytes, ".$localfiledates{$curlocalfile}." versus ".$remotefiledates{$curlocalfile}.")\n";
+ if ($doinfoonly) { print $infotext; next; }
+ if ($doverbose) { print $infotext; }
+ elsif (! $doquiet) { print "u"; }
+ }
+ elsif ($remotefilesizes{$curlocalfile} != $localfilesizes{$curlocalfile}) {
+ $dorefresh=1;
+ $infotext="Changed (different sized): ".$curlocalfile." (".$localfilesizes{$curlocalfile}." versus ".$remotefilesizes{$curlocalfile}." bytes)\n";
+ if ($doinfoonly) { print $infotext; next; }
+ if ($doverbose) { print $infotext; }
+ elsif (! $doquiet) { print "u"; }
+ }
+ if (! $dorefresh) { next; }
+ if ($dodebug) { print "Really PUTting file ".$curlocalfile."\n"; }
+ if ($ftpc->put($curlocalfile, $curlocalfile) ne $curlocalfile)
+ { print STDERR "Could not put localfile $curlocalfile\n"; }
+ my $retries = 3;
+ while ( ($ftpc->size($curlocalfile) != (lstat $curlocalfile)[7]) and ($retries-- > 0) )
+ { if (! $doquiet) { print "Re-Transfering $curlocalfile\n"; }
+ if ($ftpc->put($curlocalfile, $curlocalfile) ne $curlocalfile)
+ { print STDERR "Could not re-put localfile $curlocalfile\n"; }
+ }
+ my $newremotemdt=$ftpc->mdtm($curlocalfile)+$syncoff;
+ utime ($newremotemdt, $newremotemdt, $curlocalfile);
+ }
+ # delete files too much at the target
+ if ($doinfoonly) { print "\nWould delete obsolete remote files.\n"; }
+ elsif (! $doquiet) { print "\nDeleting obsolete remote files.\n"; }
+ my $curremotefile;
+ foreach $curremotefile (keys(%remotefiledates))
+ { if (not exists $localfiledates{$curremotefile})
+ { if ($doinfoonly) { print $curremotefile."\n"; next; }
+ if ($doverbose) { print $curremotefile."\n"; }
+ elsif (! $doquiet) { print "r"; }
+ if ($ftpc->delete($curremotefile) ne 1) { die "Could not delete remote file $curremotefile\n"; }
+ }
+ }
+ # delete dirs too much at the target
+ if ($doinfoonly) { print "\nWould delete obsolete remote directories.\n"; }
+ elsif (! $doquiet) { print "\nDeleting obsolete remote directories.\n"; }
+ my $curremotedir;
+ foreach $curremotedir (sort { return length($b) <=> length($a); } keys(%remotedirs))
+ { if (! exists $localdirs{$curremotedir})
+ { if ($doinfoonly) { print $curremotedir."\n"; next; }
+ if ($doverbose) { print $curremotedir."\n"; }
+ elsif (! $doquiet) { print "R"; }
+ if ($ftpc->rmdir($curremotedir) ne 1) { die "Could not remove remote subdirectory $curremotedir\n"; }
+ }
+ }
+ } else { # $syncdirection eq "GET"
+ # create dirs missing at the target
+ if ($doinfoonly) { print "\nWould create new local directories.\n"; }
+ elsif (! $doquiet) { print "\nCreating new local directories.\n"; }
+ my $curremotedir;
+ foreach $curremotedir (sort { return length($a) <=> length($b); } keys(%remotedirs))
+ { if (! exists $localdirs{$curremotedir})
+ { if ($doinfoonly) { print $curremotedir."\n"; next; }
+ if ($doverbose) { print $curremotedir."\n"; }
+ elsif (! $doquiet) { print "d"; }
+ mkdir($curremotedir) || die "Could not create local subdirectory $curremotedir\n";
+ }
+ }
+ # copy files missing or too old at the target, synchronize timestamp _after_ copying
+ if ($doinfoonly) { print "\nWould copy new(er) remote files.\n"; }
+ elsif (! $doquiet) { print "\nCopying new(er) remote files.\n"; }
+ my $curremotefile;
+ foreach $curremotefile (sort { return length($b) <=> length($a); } keys(%remotefiledates))
+ { my $dorefresh=0;
+ if (! exists $localfiledates{$curremotefile}) {
+ $dorefresh=1;
+ $infotext="New: ".$curremotefile." (".$remotefilesizes{$curremotefile}." bytes)\n";
+ if ($doinfoonly) { print $infotext; next; }
+ if ($doverbose) { print $infotext; }
+ elsif (! $doquiet) { print "n"; }
+ }
+ elsif ($remotefiledates{$curremotefile} > $localfiledates{$curremotefile}) {
+ $dorefresh=1;
+ $infotext="Newer: ".$curremotefile." (".$remotefilesizes{$curremotefile}." bytes, ".$remotefiledates{$curremotefile}." versus ".$localfiledates{$curremotefile}.")\n";
+ if ($doinfoonly) { print $infotext; next; }
+ if ($doverbose) { print $infotext; }
+ elsif (! $doquiet) { print "u"; }
+ }
+ elsif ($remotefilesizes{$curremotefile} != $localfilesizes{$curremotefile}) {
+ $dorefresh=1;
+ $infotext="Changed (different sized): ".$curremotefile." (".$remotefilesizes{$curremotefile}." bytes)\n";
+ if ($doinfoonly) { print $infotext; next; }
+ if ($doverbose) { print $infotext; }
+ elsif (! $doquiet) { print "c"; }
+ }
+ if (! $dorefresh) { next; }
+ if ($dodebug) { print "Really GETting file ".$curremotefile."\n"; }
+ my $rc=$ftpc->get($curremotefile, $curremotefile);
+ if ( ($rc eq undef) or ($rc ne $curremotefile) )
+ { print STDERR "Could not get file ".$curremotefile."\n"; }
+ my $retries=3;
+ while ( ($ftpc->size($curremotefile) != (lstat $curremotefile)[7]) and ($retries-- > 0) )
+ { if (! $doquiet) { print "Re-Transfering $curremotefile\n"; }
+ if ( ($rc eq undef) or ($rc ne $curremotefile) )
+ { print STDERR "Could not get file ".$curremotefile."\n"; }
+ }
+ my $newlocalmdt=$remotefiledates{$curremotefile};
+ utime ($newlocalmdt, $newlocalmdt, $curremotefile);
+ }
+ # delete files too much at the target
+ if ($doinfoonly) { print "\nWould delete obsolete local files.\n"; }
+ elsif (! $doquiet) { print "\nDeleting obsolete local files.\n"; }
+ my $curlocalfile;
+ foreach $curlocalfile (sort { return length($b) <=> length($a); } keys(%localfiledates))
+ { if (not exists $remotefiledates{$curlocalfile})
+ { if ($doinfoonly) { print $curlocalfile."\n"; next; }
+ if ($doverbose) { print $curlocalfile."\n"; }
+ elsif (! $doquiet) { print "r"; }
+ if (unlink($curlocalfile) ne 1) { die "Could not remove local file $curlocalfile\n"; }
+ }
+ }
+ # delete dirs too much at the target
+ if ($doinfoonly) { print "\nWould delete obsolete local directories.\n"; }
+ elsif (! $doquiet) { print "\nDeleting obsolete local directories.\n"; }
+ my $curlocaldir;
+ foreach $curlocaldir (keys(%localdirs))
+ { if (! exists $remotedirs{$curlocaldir})
+ { if ($doinfoonly) { print $curlocaldir."\n"; next; }
+ if ($doverbose) { print $curlocaldir."\n"; }
+ elsif (! $doquiet) { print "d"; }
+ rmdir($curlocaldir) || die "Could not remove local subdirectory $curlocaldir\n";
+ }
+ }
+ }
+}
+
+
+sub listremotedirs() {
+ if ($dodebug) {
+ print "Remote dirs (relative to ".$ftpdir."):\n";
+ my $curremotedir="";
+ foreach $curremotedir (keys(%remotedirs))
+ { print $curremotedir."/\n"; }
+ print "Remote files (relative to ".$ftpdir."):\n";
+ my $curremotefile="";
+ foreach $curremotefile (keys(%remotefiledates))
+ { print $curremotefile."\n"; }
+ print "Remote links (relative to ".$ftpdir."):\n";
+ my $curremotelink="";
+ foreach $curremotelink (keys(%remotelinks))
+ { print $curremotelink." -> ".$remotelinks{$curremotelink}."\n"; }
+ }
+}
+sub parseRemoteURL() {
+ if ($remoteURL =~ /^ftp:\/\/(([^@\/\\\:]+)(:([^@\/\\\:]+))?@)?([a-zA-Z01-9\.]+)\/(.*)/) {
+ #print "DEBUG: parsing ".$remoteURL."\n";
+ #print "match 1 = ".$1."\n";
+ #print "match 2 = ".$2."\n";
+ #print "match 3 = ".$3."\n";
+ #print "match 4 = ".$4."\n";
+ #print "match 5 = ".$5."\n";
+ #print "match 6 = ".$6."\n";
+ #print "match 7 = ".$7."\n";
+ if (length($2) > 0) { $ftpuser=$2; }
+ if (length($4) > 0) { $ftppasswd=$4; }
+ $ftpserver=$5;
+ $ftpdir=$6;
+ #if ($ftpdir eq "") { $ftpdir="/"; }
+ }
+}
+
+
+sub print_syntax() {
+ print "\n";
+ print "FTPSync.pl 1.27 (2004-08-23)\n";
+ print "\n";
+ print " ftpsync [ options ] [ localdir remoteURL ]\n";
+ print " ftpsync [ options ] [ remoteURL localdir ]\n";
+ print " options = [-dgpqv] [ cfg|ftpuser|ftppasswd|ftpserver|ftpdir=value ... ] \n";
+ print " localdir local directory, defaults to \".\".\n";
+ print " ftpURL full FTP URL, scheme\n";
+ print ' ftp://[ftpuser[:ftppasswd]@]ftpserver/ftpdir'."\n";
+ print " ftpdir is relative, so double / for absolute paths as well as /\n";
+ print " -c | -C like -i, but then prompts whether to actually do work\n";
+ print " -d | -D turns debug output (including verbose output) on\n";
+ print " -g | -G forces sync direction to GET (remote to local)\n";
+ print " -h | -H turns debugging on\n";
+ print " -i | -I forces info mode, only telling what would be done\n";
+ print " -p | -P forces sync direction to PUT (local to remote)\n";
+ print " -q | -Q turnes quiet operation on\n";
+ print " -v | -V turnes verbose output on\n";
+ print " cfg= read parameters and options from file defined by value.\n";
+ print " ftpserver= defines the FTP server, defaults to \"localhost\".\n";
+ print " ftpdir= defines the FTP directory, defaults to \".\" (/wo '\"') \n";
+ print " ftpuser= defines the FTP user, defaults to \"ftp\".\n";
+ print " ftppasswd= defines the FTP password, defaults to \"anonymous\".\n";
+ print "\n";
+ print " Later mentioned options and parameters overwrite those mentioned earlier.\n";
+ print " Command line options and parameters overwrite those in the config file.\n";
+ print " Don't use '\"', although mentioned default values might motiviate you to.\n";
+ print "\n";
+}
+
+
+sub print_options() {
+ print "\nPrinting options:\n";
+ # meta
+ print "returncode = ", $returncode , "\n";
+ print "configfile = ", $configfile , "\n";
+ # basiscs
+ print "syncdirection = ", $syncdirection , "\n";
+ print "localdir = ", $localdir , "\n";
+ # FTP stuff
+ print "remoteURL = ", $remoteURL , "\n";
+ print "ftpuser = ", $ftpuser , "\n";
+ print "ftppasswd = ", $ftppasswd , "\n";
+ print "ftpserver = ", $ftpserver , "\n";
+ print "ftpdir = ", $ftpdir , "\n";
+ # verbsityosity
+ print "doverbose = ", $doverbose , "\n";
+ print "dodebug = ", $dodebug , "\n";
+ print "doquiet = ", $doquiet , "\n";
+ #
+ print "doinfoonly = ", $doinfoonly , "\n";
+ print "\n";
+}