INN commit: branches/2.4 (4 files)
INN Commit
Russ_Allbery at isc.org
Sun Apr 6 09:38:31 UTC 2008
Date: Sunday, April 6, 2008 @ 02:38:31
Author: iulius
Revision: 7739
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:
branches/2.4/doc/man/simpleftp.1
branches/2.4/doc/pod/simpleftp.pod
branches/2.4/scripts/Makefile
branches/2.4/scripts/simpleftp.in
-----------------------+
doc/man/simpleftp.1 | 28 +++++++++++--------
doc/pod/simpleftp.pod | 26 +++++++++---------
scripts/Makefile | 2 -
scripts/simpleftp.in | 69 +++++++++++++++++++++++++-----------------------
4 files changed, 67 insertions(+), 58 deletions(-)
Modified: doc/man/simpleftp.1
===================================================================
--- doc/man/simpleftp.1 2008-04-06 09:33:33 UTC (rev 7738)
+++ doc/man/simpleftp.1 2008-04-06 09:38:31 UTC (rev 7739)
@@ -137,32 +137,36 @@
\&\fBsimpleftp\fR \fIurl\fR [...]
.SH "DESCRIPTION"
.IX Header "DESCRIPTION"
-\&\fBsimpleftp\fR is a Perl script script that provides basic support for
+\&\fBsimpleftp\fR is a Perl script that provides basic support for
fetching files with \s-1FTP\s0 in a batch oriented fashion. It takes one or more
-\&\s-1FTP\s0 \s-1URLS\s0 on the command line. The file(s) will be retrieved from the
+\&\s-1FTP\s0 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., \f(CW\*(C`ftp://ftp.isc.org/pub/usenet/CONFIG/active.gz\*(C'\fR
+as on the remote; e.g., <ftp://ftp.isc.org/pub/usenet/CONFIG/active.gz>
is stored as \fIactive.gz\fR in the current directory.
+.PP
+The script properly understands usernames, passwords and ports specified
+as follows:
+.PP
+.Vb 1
+\& ftp://user:password@host:port/path/file
+.Ve
.SH "BUGS"
.IX Header "BUGS"
\&\fBsimpleftp\fR is an extremely poor substitute for more complete programs
like the freely available \fBwget\fR or \fBncftp\fR utilities. It was written
only to provide elementary support in \s-1INN\s0 for non-interactive fetching of
-the files in <ftp://ftp.isc.org/pub/usenet/CONFIG/> without requiring
+the files in <ftp://ftp.isc.org/pub/pgpcontrol/> or
+<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 \fBsimpleftp\fR does not understand the complete syntax of URLs,
-only the hostname and pathname parts \*(-- it will not understand username,
-password, port or parameter strings.
-.PP
-The Perl libraries that it uses have the advantage of coming with Perl,
-even older versions of Perl, but are not \f(CW\*(C`\-w\*(C'\fR safe and do not work nearly
-as well as Net::FTP.
+out is that downloaded files by \fBsimpleftp\fR override existing files
+with the same name in the local directory.
.SH "HISTORY"
.IX Header "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>.
.PP
$Id$
.SH "SEE ALSO"
.IX Header "SEE ALSO"
-\&\fIactsync\fR\|(8)
+\&\fIactsync\fR\|(8).
Modified: doc/pod/simpleftp.pod
===================================================================
--- doc/pod/simpleftp.pod 2008-04-06 09:33:33 UTC (rev 7738)
+++ doc/pod/simpleftp.pod 2008-04-06 09:38:31 UTC (rev 7739)
@@ -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 -- 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 2008-04-06 09:33:33 UTC (rev 7738)
+++ scripts/Makefile 2008-04-06 09:38:31 UTC (rev 7739)
@@ -74,6 +74,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 2008-04-06 09:33:33 UTC (rev 7738)
+++ scripts/simpleftp.in 2008-04-06 09:38:31 UTC (rev 7739)
@@ -1,34 +1,25 @@
-#! /usr/bin/perl
-# fixscript will replace this line with require innshellvars.pl
+#! /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