about summary refs log tree commit
diff options
context:
space:
mode:
authorGraham Barr <gbarr@pobox.com>1999-05-05 07:08:07 +0000
committerGraham Barr <gbarr@pobox.com>1999-05-05 07:08:07 +0000
commit6e20c7178b991896e16f76de3ff218a4dd2358b9 (patch)
tree452b43896b9b58f8db8febe68e5832b1d913b5d9
parent14fa89ca573adc2de041fbd67e96b71d62d91fda (diff)
downloadperl-libnet-6e20c7178b991896e16f76de3ff218a4dd2358b9.tar.gz
Net::FTP
- Check that writes to local file succeed

-rw-r--r--Net/FTP.pm18
1 files changed, 13 insertions, 5 deletions
diff --git a/Net/FTP.pm b/Net/FTP.pm
index 376de49..d2b9aa1 100644
--- a/Net/FTP.pm
+++ b/Net/FTP.pm
@@ -21,7 +21,7 @@ use Net::Cmd;
 use Net::Config;
 # use AutoLoader qw(AUTOLOAD);
 
-$VERSION = "2.52"; # $Id: //depot/libnet/Net/FTP.pm#38 $
+$VERSION = "2.52"; # $Id: //depot/libnet/Net/FTP.pm#39 $
 @ISA     = qw(Exporter Net::Cmd IO::Socket::INET);
 
 # Someday I will "use constant", when I am not bothered to much about
@@ -406,26 +406,34 @@ sub get
   {
    carp "Cannot binmode Local file $local: $!\n";
    $data->abort;
+   close($loc) unless $localfd;
    return undef;
   }
 
  $buf = '';
- my $swlen;
  my($count,$hashh,$hashb,$ref) = (0);
 
  ($hashh,$hashb) = @$ref
    if($ref = ${*$ftp}{'net_ftp_hash'});
 
- do
+ while(1)
   {
-   $len = $data->read($buf,1024);
+   last unless $len = $data->read($buf,1024);
    if($hashh) {
     $count += $len;
     print $hashh "#" x (int($count / $hashb));
     $count %= $hashb;
    }
+   my $written = syswrite($loc,$buf,$len);
+   unless(defined($written) && $written == $len)
+    {
+     carp "Cannot write to Local file $local: $!\n";
+     $data->abort;
+     close($loc)
+        unless defined $localfd;
+     return undef;
+    }
   }
- while($len && defined($swlen = syswrite($loc,$buf,$len)) && $swlen == $len);
 
  print $hashh "\n" if $hashh;