INN commit: trunk (3 files)

INN Commit Russ_Allbery at isc.org
Thu Sep 20 20:12:55 UTC 2007


    Date: Thursday, September 20, 2007 @ 13:12:55
  Author: iulius
Revision: 7685

Rewrite simpleftp to use Net::FTP.
Indeed, ftp.pl is no longer shipped with Perl 5 and the script
does not work.

  * Add support for usernames, passwords and ports.
  * Fix typos in the documentation.
  * Remove the use of fixscript on simpleftp.
  * Perl warnings are now on.

Modified:
  trunk/doc/pod/simpleftp.pod
  trunk/scripts/Makefile
  trunk/scripts/simpleftp.in

-----------------------+
 doc/pod/simpleftp.pod |   26 +++++++++---------
 scripts/Makefile      |    2 -
 scripts/simpleftp.in  |   69 +++++++++++++++++++++++++-----------------------
 3 files changed, 51 insertions(+), 46 deletions(-)

Modified: doc/pod/simpleftp.pod
===================================================================
--- doc/pod/simpleftp.pod	2007-09-19 11:24:28 UTC (rev 7684)
+++ doc/pod/simpleftp.pod	2007-09-20 20:12:55 UTC (rev 7685)
@@ -8,37 +8,39 @@
 
 =head1 DESCRIPTION
 
-B<simpleftp> is a Perl script script that provides basic support for
+B<simpleftp> is a Perl script that provides basic support for
 fetching files with FTP in a batch oriented fashion.  It takes one or more
-FTP URLS on the command line.  The file(s) will be retrieved from the
+FTP URLs on the command line.  The file(s) will be retrieved from the
 remote server and placed in the current directory with the same basename
-as on the remote; e.g., C<ftp://ftp.isc.org/pub/usenet/CONFIG/active.gz>
+as on the remote; e.g., L<ftp://ftp.isc.org/pub/usenet/CONFIG/active.gz>
 is stored as F<active.gz> in the current directory.
 
+The script properly understands usernames, passwords and ports specified
+as follows:
+
+    ftp://user:password@host:port/path/file
+
 =head1 BUGS
 
 B<simpleftp> is an extremely poor substitute for more complete programs
 like the freely available B<wget> or B<ncftp> utilities.  It was written
 only to provide elementary support in INN for non-interactive fetching of
-the files in L<ftp://ftp.isc.org/pub/usenet/CONFIG/> without requiring
+the files in L<ftp://ftp.isc.org/pub/pgpcontrol/> or
+L<ftp://ftp.isc.org/pub/usenet/CONFIG/> without requiring
 administrators to install yet another package.  Its shortcomings as a
 general purpose program are too numerous to mention, but one that stands
-out is that B<simpleftp> does not understand the complete syntax of URLs,
-only the hostname and pathname parts S<-- it> will not understand username,
-password, port or parameter strings.
+out is that downloaded files by B<simpleftp> override existing files
+with the same name in the local directory.
 
-The Perl libraries that it uses have the advantage of coming with Perl,
-even older versions of Perl, but are not C<-w> safe and do not work nearly
-as well as Net::FTP.
-
 =head1 HISTORY
 
 Tossed off by David C Lawrence <tale at isc.org> for InterNetNews.
+Rewritten to use Net::FTP by Julien Elie <julien at trigofacile.com>.
 
 $Id$
 
 =head1 SEE ALSO
 
-actsync(8)
+actsync(8).
 
 =cut

Modified: scripts/Makefile
===================================================================
--- scripts/Makefile	2007-09-19 11:24:28 UTC (rev 7684)
+++ scripts/Makefile	2007-09-20 20:12:55 UTC (rev 7685)
@@ -59,6 +59,6 @@
 innwatch:	innwatch.in      $(FIX)	; $(FIX) innwatch.in
 rc.news:	rc.news.in       $(FIX)	; $(FIX) rc.news.in
 scanlogs:	scanlogs.in      $(FIX)	; $(FIX) scanlogs.in
-simpleftp:	simpleftp.in     $(FIX)	; $(FIX) simpleftp.in
+simpleftp:	simpleftp.in     $(FIX)	; $(FIX) -i simpleftp.in
 tally.control:	tally.control.in $(FIX)	; $(FIX) tally.control.in
 writelog:	writelog.in      $(FIX)	; $(FIX) writelog.in

Modified: scripts/simpleftp.in
===================================================================
--- scripts/simpleftp.in	2007-09-19 11:24:28 UTC (rev 7684)
+++ scripts/simpleftp.in	2007-09-20 20:12:55 UTC (rev 7685)
@@ -1,34 +1,25 @@
-#! /usr/bin/perl
-# fixscript will replace this line with code to load INN::Config
+#! /usr/bin/perl -w
 
-# simpleftp
-# Author: David Lawrence <tale at isc.org>
+# simpleftp - Rudimentary FTP client.
 #
+# Author: David Lawrence <tale at isc.org>.
+#         Rewritten by Julien Elie <julien at trigofacile.com> to use Net::FTP.
+#
 # Fetch files to the local machine based on URLs on the command line.
-# Uses perl's ftp.pl, which in turn uses chat2.pl.  Not very speedy.
-#   There is a better perl ftp module in the libnet package,
-# but it would require the INN admin to install yet another package.
-#   There is a perl www module which can do ftp in the libwww package,
-# but that has the same issue as the libnet module.
-#   INN's configure searches for ncftp, wget, linx, et cetera,
+# INN's configure searches for ncftp, wget, linx, et caetera,
 # but they're all system add-ons, so this is provided.
-#   Perl5 is already required by other parts of INN, it only took a half hour
+#
+# Perl 5 is already required by other parts of INN; it only took a half hour
 # to write this, so this was the easiest way to go for a backup plan.
-#   This script is nowhere near as flexible as libwww.  If you really need
+#
+# This script is nowhere near as flexible as libwww.  If you really need
 # that kind of power, get libwww and use it.  This is just sufficient for what
 # INN needed.
 
-# NOTE: ftp.pl and chat2.pl are not -w safe (uninitialized values errors)
-
 use strict;
+use Net::FTP;
 use Sys::Hostname;
 
-# $ENV{'PATH'} = '/bin:/usr/bin:/usr/ucb';
-
-# trick ftp.pl into not demanding this file.
-$INC{'sys/socket.ph'} = 1;
-require 'ftp.pl';
-
 $0 =~ s(.*/)();
 
 my $usage = "Usage: $0 ftp-URL ...\n";
@@ -41,47 +32,59 @@
     or die $usage;
 }
 
-my ($user, $pass, $lasthost);
+my ($lasthost, $ftp);
 
-$user = 'anonymous';
-$pass = (getpwuid($<))[0] . '@' . hostname;
-
-# this will keep track of how many _failed_
+# This will keep track of how many _failed_.
 my $exit = @ARGV;
 
 for (@ARGV) {
   my ($host, $path) = m%^ftp://([^/]+)(/.+)%;
+  my $user = 'anonymous';
+  my $pass = (getpwuid($<))[0] . '@' . hostname;
+  my $port = 21;
+
   unless (defined $host && defined $path) {
     warn "$0: bad URL: $_\n";
     next;
   }
 
-  # NOTE: URLs with usernames, passwords, ports or parameters are not supported
+  if ($host =~ /(.*):(.*)\@(.*)/) {
+    $user = $1;
+    $pass = $2;
+    $host = $3;
+  }
 
+  if ($host =~ /(.*):(.*)/) {
+    $port = $1;
+    $host = $2;
+  }
+
   if (defined $lasthost && $host ne $lasthost) {
-    ftp::close();
+    $ftp->quit;
     $lasthost = undef;
   }
 
   unless (defined $lasthost) {
-    ftp::open($host, getservbyname('ftp', 'tcp') || 21, 0, 1)
+    $ftp = Net::FTP->new($host, Port => $port)
       or next;
-    ftp::login($user, $pass)
+    $ftp->login($user, $pass)
       or next;
-    ftp::type("i")
-      or next;
   }
 
   my $localfile = $path;
+  $path =~ s([^/]+$)();
   $localfile =~ s(.*/)();
-  ftp::get($path, $localfile)
+
+  $ftp->cwd($path)
     or next;
+  $ftp->get($localfile)
+    or next;
 
   $exit--;
   $lasthost = $host;
 }
 
-ftp::close()
+$ftp->quit
   if defined $lasthost;
 
 exit $exit;



More information about the inn-committers mailing list