From 6e20c7178b991896e16f76de3ff218a4dd2358b9 Mon Sep 17 00:00:00 2001 From: Graham Barr Date: Wed, 5 May 1999 07:08:07 +0000 Subject: Net::FTP - Check that writes to local file succeed --- Net/FTP.pm | 18 +++++++++++++----- 1 file 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; -- cgit v1.2.3-24-ge0c7