ademmler has asked for the wisdom of the Perl Monks concerning the following question:

Hi monks, I need help with Net::FTP. I can't work out how to get the amount of transfered data while up- and download. Does any body has a working sample? Regards and thanks Alex

Replies are listed 'Best First'.
Re: Net::FTP trace uploaded data
by Khen1950fx (Canon) on Apr 15, 2008 at 04:25 UTC
    I've read your question---it's still unclear to me; however, you can get the size of a file, whether a transfered file or whatever something like this. For example, I want to find out the size of Net::FTP:

    print "file size ", -s '/usr/lib/perl5/5.8.8/Net/FTP.pm', " bytes\n";

      Hi Khen.
      Thanks for your hint, but I have ment something different. I need advice how to use the datacon class from Net::FTP to get the amount of transfereed data (while transfering). I have read the CPAN docu, but I have no glue what the aouther is telling me. Best would be a working sample - for me.
      Regards Ademmler

      #From the manual:
      read ( BUFFER, SIZE , TIMEOUT )
      Read SIZE bytes of data from the server and place it into BUFFER, also performing any <CRLF> translation necessary. TIMEOUT is optional, if not given, the timeout value from the command connection will be used. Returns the number of bytes read before any <CRLF> translation.
      write ( BUFFER, SIZE , TIMEOUT )
      Write SIZE bytes of data from BUFFER to the server, also performing any <CRLF> translation necessary. TIMEOUT is optional, if not given, the timeout value from the command connection will be used. Returns the number of bytes written before any <CRLF> translation.
      bytes_read ()
      Returns the number of bytes read so far.
Re: Net::FTP trace uploaded data
by poolpi (Hermit) on Apr 15, 2008 at 10:36 UTC

    A simple example :
    See the Net::FTP source for more details

    #!/usr/bin/perl -w use strict; use Net::FTP; use Fcntl qw(O_WRONLY O_RDONLY O_APPEND O_CREAT O_TRUNC); my $dns = 'ftp.squarepants.com'; my $user = 'SpongeBob'; my $passwd = '3xtr&Dry'; my $dir = 'under/pacifiq/ocean/'; my $ftp = Net::FTP->new( $dns, Debug => 0 ) or die "Cannot connect to $dns: $@"; $ftp->login( $user, $passwd ) or die "Cannot login ", $ftp->message; $ftp->cwd($dir) or die "Cannot change working directory ", $ftp->message; my ( $loc, $buf, $data ); my ( $remote, $local ); $remote = $local = 'BikiniBottom.png'; $data = $ftp->retr($remote) or die "unable to retrieve $remote\n"; unless ( sysopen( $loc, $local, O_WRONLY | O_TRUNC | O_CREAT ) ) { die "Cannot open $local: $!\n"; } while ( my $len = $data->read( $buf, 2048 ) ) { printf( " %d bytes read\n", $len ); unless ( print $loc $buf ) { die "Cannot write to $local: $!\n"; $data->abort; close($loc); } } print "Total read : ", $data->bytes_read(), "\n"; $data->close; $ftp->quit;

    hth,
    PooLpi

    'Ebry haffa hoe hab im tik a bush'. Jamaican proverb
      Dear PooLpi!
      I just want to say "thank you verry much". Your sample helped me so much to understand this functionality.
      Ademmler
      Dear PooLpi,
      you may have also a sample how to send a file and trace the data? Sorry, that I am asking, but I do not know about "sysopen" and IO stuff.
      Thank you very much
      ADemmler