Monitoring file size during net::ftp 
Author Message
 Monitoring file size during net::ftp

All, I'm using the following to ftp a file from a PC to a unix machine.

 $ftp = Net::FTP->new("$address");
 $ftp->login("$username","$passwd");
 $ftp->cwd("$source");
 $ftp->hash(TRUE);
 $ftp->binary();
 $ftp->put("$filename");
 $ftp->quit;

However, I need to be able to monitor the progress of the ftp,
specifically, the amount of data that has been ftp'd.

How would I go about this?  I know the hash output goes to STDERR.  Is
there a way to grab the output and process it?

Thanks for any help,
Kevin Ketchum



Thu, 13 Feb 2003 03:00:00 GMT  
 Monitoring file size during net::ftp
[posted to comp.lang.perl.modules]

Quote:

>All, I'm using the following to ftp a file from a PC to a unix machine.

(snip code sample for brevity)

Quote:
>However, I need to be able to monitor the progress of the ftp,
>specifically, the amount of data that has been ftp'd.

You can use the stor() and write() methods and push the bytes (counting
them at the same time) yourself. Here's a trivial example that prints a
plus symbol every 5000 bytes, and reports the total number of bytes sent at
the end of the transfer:

#!/usr/local/bin/perl -w

use Net::FTP;
use strict;

my $local_file = shift;
my $remote_file = shift;
$|++; # turn off buffering if you want immediate feedback


$ftp->login('user','pass') or die $ftp->message;
$ftp->cwd('/wherever') or die $ftp->message;
$ftp->binary;
open IN, "<$local_file" or die "Oops - can't open input file: $!\n";
binmode IN; # only required for binary files on Windoze
my $rfd = $ftp->stor($remote_file) or die $ftp->message;
my $sent;
while (read IN, my $buf, 1000)
{
   $sent += $rfd->write($buf, length($buf));
   print '+' unless $sent % 5000;

Quote:
}

print "\n$sent bytes transferred\n";

close IN;
$rfd->close;
$ftp->quit;
__END__

Quote:
>How would I go about this?  I know the hash output goes to STDERR.  Is
>there a way to grab the output and process it?

Well, you could do that too, but is that what you really want?

--
 - Jeff Drumm



Thu, 13 Feb 2003 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Differences in the file size reported by Net::FTP->size and ls -l

2. file size limits of perl Net::ftp

3. Net::FTP File Size Limit?

4. Net::FTP -- hash printing during get()

5. Net::FTP locks up during put

6. CGI.pm Bug: file upload file size mismatch when file size is close to buffer size

7. SIZE command and Net::FTP module

8. NET::FTP How to FTP all files of a current filetype

9. $ftp->put stores empty file (Net::FTP)

10. FTP files without Net::FTP?

11. Can't get size value back when using $ftp->size

12. NET::SSH, NET::FTP, NET::POP3 (how to detect)

 

 
Powered by phpBB® Forum Software