As a variation on using bytes_read(), one can use methods of the dataconn class of Net::FTP to report periodic progress of the transfer. For example, assuming an $ftp object has been created, one can use the read method for getting a file:
my $file = 'some_file'; my $size = $ftp->size($file); my $bsize = 1024; my $report_size = $bsize * 1000; my ($len, $buffer); my $so_far = 0; my $chunk_size = 0; $ftp->binary; my $data = $ftp->retr($file); open(my $fh, '>', $file) or die qq{Cannot open $file: $!}; binmode $fh; do { $len = $data->read($buffer, $bsize); $so_far += $len; $chunk_size += $len; if ($chunk_size >= $report_size) { printf("Downloaded %d / %d so far\n", $so_far, $size); $chunk_size = 0; } } while ($len > 0 && syswrite($fh, $buffer, $len) == $len); print "Done!\n"; close($fh); $data->close;
while for uploading a file one can use the write method:
my $file = 'some_file'; my $size = -s $file; my $bsize = 1024; my $report_size = $bsize * 1000; my ($len, $buffer); my $so_far = 0; my $chunk_size = 0; $ftp->binary; my $data = $ftp->stor($file); open(my $fh, '<', $file) or die qq{Cannot open $file: $!}; binmode $fh; while (sysread $fh, $buffer = "", $bsize) { $len = $data->write($buffer, length($buffer)); $so_far += $len; $chunk_size += $len; if ($chunk_size >= $report_size) { printf("Uploaded %d / %d so far\n", $so_far, $size); $chunk_size = 0; } } print "Done!\n"; close($fh); $data->close;

In reply to Re^2: Asynchronous FTP 2 by randyk
in thread Asynchronous FTP 2 by ariel2

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.