in reply to Obtaining statistics for Net::FTP transfers

May I suggest some ways to approach your problems. Firstly, have a good read of the Net::FTP documentation.

Size: how big is a file? Well, if you are downloading the file, you can use the Net::FTP->size() function. If you are uploading a file, you can use the stat function (type perldoc -f stat for more information).

Transfer duration: this shouldn't be too hard! Get the time (look at the time function) before you start the transfer, and subtract that from the time at the end of the transfer! Easy!

Transfer speed: quite simply is file size divided by transfer time. Again, so basic, I'm wondering why you asked this.. maybe you want this value in real time? If so.. refer to the module documentation again! There is an option to the ->New() function called Hash that will notify you every time 1024 bytes are transferred. Read about it!

Here's an example on how to get the size of files using Net::FTP (tested):

use Net::FTP; use strict; my $f = Net::FTP->new( Host => "cs.ucl.ac.uk", Firewall => "webproxy.local", FirewallType => 1, Passive => 1, ); $f->login( "anonymous", "myemail\@mycompany.com" ) or die( "Failed to log in to FTP server: " . $f->message ); my @list = $f->ls( '/rfc' ); foreach my $fname ( @list ) { my $size = $f->size( '/rfc/' . $fname ); defined( $size ) or die( " Failed to get size: " . $f->message ); print( " Size of $fname is $size\n" ); } $f->quit();

Replies are listed 'Best First'.
Re^2: Obtaining statistics for Net::FTP transfers
by qragamu (Initiate) on Sep 06, 2007 at 10:11 UTC
    Thanks, I already had Net::FTP->size() and perldoc -f stat, I was just hoping that there was an option in Net::FTP that I hadn't seen that produced the same printout as a manual session. I am using the 'time' as well, but I require millisecond accuracy. I know, then I should load the Time::HiRes Module. Tried that, but it needs a C complier and that's a no-no on the test system. So then I found a pre-compiled version ( as suggested by the Module's author ), but perl complains 'Can't locate loadable object for module Time::HiRes in @INC...etc' which is not very helpful.