about summary refs log tree commit
diff options
context:
space:
mode:
authorGraham Barr <gbarr@pobox.com>2008-02-10 01:08:12 +0000
committerGraham Barr <gbarr@pobox.com>2009-02-24 10:40:49 -0600
commit39957c670d96586b0e11091cc2deaa8409d120c8 (patch)
tree3dc07f841a6e10d0403a44aecfb4c31ecf200056
parent0d616e68ccd1acba2203847af1c6b59f8134e37f (diff)
downloadperl-libnet-39957c670d96586b0e11091cc2deaa8409d120c8.tar.gz
Avoid warnings when server do not prefix messages with codes
-rw-r--r--Net/Cmd.pm2
-rw-r--r--Net/FTP.pm8
2 files changed, 7 insertions, 3 deletions
diff --git a/Net/Cmd.pm b/Net/Cmd.pm
index 639a8a9..727b677 100644
--- a/Net/Cmd.pm
+++ b/Net/Cmd.pm
@@ -353,6 +353,7 @@ sub response {
     ($code, $more) = $cmd->parse_response($str);
     unless (defined $code) {
       $cmd->ungetline($str);
+      $@ = $str;   # $@ used as tunneling hack
       last;
     }
 
@@ -363,6 +364,7 @@ sub response {
     last unless ($more);
   }
 
+  return undef unless defined $code;
   substr($code, 0, 1);
 }
 
diff --git a/Net/FTP.pm b/Net/FTP.pm
index ee31441..27851b5 100644
--- a/Net/FTP.pm
+++ b/Net/FTP.pm
@@ -107,7 +107,8 @@ sub new {
 
   unless ($ftp->response() == CMD_OK) {
     $ftp->close();
-    $@ = $ftp->message;
+    # keep @$ if no message. Happens, when response did not start with a code.
+    $@ = $ftp->message || $@;
     undef $ftp;
   }
 
@@ -1091,7 +1092,7 @@ sub command {
 
 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);
@@ -1107,8 +1108,9 @@ sub parse_response {
   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);
 }