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

if you do a normal ftp and get a file ftp usually shows this information

226 Transfer complete. local: file.DAT remote: file.DAT 92191338 bytes sent in 7.8 seconds (11475.52 Kbytes/s)

how can i get this information be recorded in ftp.log using MNet::FTP

perl >>ftp.log -MNet::FTP -e ' ( $host, $user, $pass ) = @ARGV; $ftp = Net::FTP->new($host) or die "$@\n"; $ftp->login( $user, $pass ) or die $ftp->message; $ftp->binary; @files = $ftp->ls; $ftp->get($_) for @files; $ftp->quit or die $ftp->message; ' <host> <user> <pass>

Replies are listed 'Best First'.
Re: higher info lever for MNet::FTP
by roboticus (Chancellor) on Jun 30, 2010 at 22:21 UTC

    Since the local and remote file names are arguments for sending and receiving the files, you can simply print them. For the file size, a simpleperldoc Net::FTP reveals several methods that may help you find the file size, such as size or bytes_read. Alternatively, you can simply ask the local filesystem for the size (perldoc -f stat)of the file after you put/get the file.

    Creative searching through perldoc perlfunc and or http://cpan.org will let you find some functions to help you work with the times.

    By the way: The module is Net::FTP, not MNet::FTP.

    ...roboticus

      Thanks Roboticus, for your suggestions, but I'm a complete newbie on perl world, someone gave this code that i try to improve. I'm RTFM but it's overwhelming

Re: higher info lever for MNet::FTP
by Khen1950fx (Canon) on Jul 01, 2010 at 06:13 UTC
    Writng code for an ftp log involves way too much coding to suit me; hence, I tried an easier way by BrowserUk. It'll record the number of bytes and seconds in the log.
    #!/usr/bin/perl use strict; use warnings; use Time::HiRes qw[time]; use Net::FTP; use constant HOST => 'ftp.perl.org'; use constant DIR => '/pub/CPAN/ports/win32/Standard/x86'; use constant FILE => 'perl-5.6.0.tar.gz'; our $SIZE ||= 4096; my $start = time; my $ftp = Net::FTP->new( HOST, Passive => 1, Timeout => 1, Bytes_read => $SIZE, BlockSize => $SIZE, ) or die "Couldn't connect: $@\n"; $ftp->login('anonymous'); $ftp->cwd(DIR); $ftp->binary; $ftp->ls(FILE); my $size = $ftp->size(FILE); $ftp->quit; open(STDOUT, '>', 'Log.txt'); printf "Got %d bytes at %.3f/second\n", $size, $size / ( time() - $start );