perl/perl-gracefull-net-ftp.diff

67 lines
1.9 KiB
Diff
Raw Normal View History

This patch avoids several silly warnings, and fills $res->status_line with something useful
in case your FTP server babbles some text message without a leading response code.
Seen from ftp.opensuse.org:
connect(3, {sa_family=AF_INET, sin_port=htons(21), sin_addr=inet_addr("195.135.221.134")}, 16) = 0
read(3, "This server is busy, please try again later or any of my mirrors: http://download.opensuse.org\n\n", 1024) = 96
Note the missing "500 " before "This".
Command line ftp clients handle this gracefully, so should we.
With this patch, LWP clients see a status_line of "500 This server is busy, ..."
2006-12-20, jw@suse.de
--- perl-5.8.8/lib/Net/FTP.pm.orig 2006-12-20 21:09:01.075906000 +0100
+++ perl-5.8.8/lib/Net/FTP.pm 2006-12-20 21:09:17.324643000 +0100
@@ -119,7 +119,7 @@
unless ($ftp->response() == CMD_OK)
{
$ftp->close();
- $@ = $ftp->message;
+ $@ = $ftp->message || $@; # keep @$ if no message. Happens, when response did not start with a code.
undef $ftp;
}
@@ -1107,7 +1107,7 @@
sub response
{
my $ftp = shift;
- my $code = $ftp->SUPER::response();
+ my $code = $ftp->SUPER::response() || 5; # assume 500 if undef
delete ${*$ftp}{'net_ftp_pasv'}
if ($code != CMD_MORE && $code != CMD_INFO);
@@ -1122,9 +1122,11 @@
my $ftp = shift;
+
# Darn MS FTP server is a load of CRAP !!!!
+ # Expect to see undef here.
return ()
- unless ${*$ftp}{'net_cmd_code'} + 0;
+ unless 0 + (${*$ftp}{'net_cmd_code'}||0);
(${*$ftp}{'net_cmd_code'},1);
}
--- perl-5.8.8/lib/Net/Cmd.pm.orig 2006-12-20 21:09:05.850129000 +0100
+++ perl-5.8.8/lib/Net/Cmd.pm 2006-12-20 21:09:17.332631000 +0100
@@ -338,9 +338,11 @@
if ($cmd->debug);
($code,$more) = $cmd->parse_response($str);
+
unless(defined $code)
{
$cmd->ungetline($str);
+ $@ = $str; # $@ is used as a tunneling hack.
last;
}
@@ -351,6 +353,7 @@
last unless($more);
}
+ return undef unless defined $code;
substr($code,0,1);
}