diff options
author | Graham Barr <gbarr@pobox.com> | 1998-04-19 00:00:38 +0000 |
---|---|---|
committer | Graham Barr <gbarr@pobox.com> | 1998-04-19 00:00:38 +0000 |
commit | 766d74d39140f5c120cde5ba6b1e435a2f22953b (patch) | |
tree | 9ee323684fde7dfd21511dd23e0f3e827574feb3 | |
parent | 81a5363e0e7948178762c8c2557fa95940afbfeb (diff) | |
download | perl-libnet-766d74d39140f5c120cde5ba6b1e435a2f22953b.tar.gz |
Net::FTP
- Enhanced ->size() to try different approaces if SIZE is not implemented
-rw-r--r-- | Net/FTP.pm | 32 |
1 files changed, 26 insertions, 6 deletions
@@ -21,7 +21,7 @@ use Net::Cmd; use Net::Config; # use AutoLoader qw(AUTOLOAD); -$VERSION = "2.39"; # $Id: //depot/libnet/Net/FTP.pm#23 $ +$VERSION = "2.39"; # $Id: //depot/libnet/Net/FTP.pm#24 $ @ISA = qw(Exporter Net::Cmd IO::Socket::INET); # Someday I will "use constant", when I am not bothered to much about @@ -167,10 +167,30 @@ sub size { my $ftp = shift; my $file = shift; - - $ftp->_SIZE($file) - ? ($ftp->message =~ /(\d+)/)[0] - : undef; + my $io; + if($ftp->supported("SIZE")) { + return $ftp->_SIZE($file) + ? ($ftp->message =~ /(\d+)/)[0] + : undef; + } + elsif($ftp->supported("STAT")) { + my @msg; + return undef + unless $ftp->_STAT($file) && (@msg = $ftp->message) == 3; + my $line; + foreach $line (@msg) { + return (split(/\s+/,$line))[4] + if $line =~ /^[-rw]{10}/ + } + } + elsif($io = $ftp->list($file)) { + my $line; + $io->read($line,1024); + $io->close; + return (split(/\s+/,$1))[4] + if $line =~ /^([-rw]{10}.*)\n/s; + } + undef; } sub login @@ -924,6 +944,7 @@ sub _RESP { shift->command("RESP",@_)->response() == CMD_OK } sub _MDTM { shift->command("MDTM",@_)->response() == CMD_OK } sub _SIZE { shift->command("SIZE",@_)->response() == CMD_OK } sub _HELP { shift->command("HELP",@_)->response() == CMD_OK } +sub _STAT { shift->command("STAT",@_)->response() == CMD_OK } sub _APPE { shift->command("APPE",@_)->response() == CMD_INFO } sub _LIST { shift->command("LIST",@_)->response() == CMD_INFO } sub _NLST { shift->command("NLST",@_)->response() == CMD_INFO } @@ -940,7 +961,6 @@ sub _ALLO { shift->unsupported(@_) } sub _SMNT { shift->unsupported(@_) } sub _MODE { shift->unsupported(@_) } sub _SYST { shift->unsupported(@_) } -sub _STAT { shift->unsupported(@_) } sub _STRU { shift->unsupported(@_) } sub _REIN { shift->unsupported(@_) } |