Hello monks, I am trying to use Net::SFTP to grab a couple of files off a remote server and show the progress in percent downloaded, but what my script displays is incorrect.

Here is basically what I am trying to due:

#!/usr/bin/perl use strict; use warnings; use Net::SFTP; my %args = ( user => 'me', password => 'xxxxxxxxxx' ); my $sftp = Net::SFTP->new( 'ftp.example.com', %args ) || die 'Could no +t connect to the server: ' . $! . "\n"; $sftp->get( 'file1.txt', 'file1.txt', \&callback ) || die 'Could not f +etch remote file: ' . $! . "\n"; sub callback { my ( $sftp, $data, $offset, $size ) = @_; my $percent = ($offset/$size)*100; print $percent . ' '; return; }

The output of the print is:

0 409600/333487 819200/333487 1228800/333487 1638400/333487 2048000/333487 2457600/333487 409600/47641 3276800/333487 3686400/333487 4096000/333487 409600/30317 4915200/333487 5324800/333487 819200/47641 6144000/333487 6553600/333487 6963200/333487 7372800/333487 7782400/333487 8192000/333487 1228800/47641 819200/30317 9420800/333487 9830400/333487 10240000/333487 10649600/333487 11059200/333487 1638400/47641 11878400/333487 12288000/333487 12697600/333487 13107200/333487 1228800/30317 13926400/333487 2048000/47641 14745600/333487 15155200/333487 15564800/333487 15974400/333487 16384000/333487 16793600/333487 2457600/47641 17612800/333487 1638400/30317 18432000/333487 18841600/333487 19251200/333487 19660800/333487 2867200/47641 20480000/333487 20889600/333487 21299200/333487 21708800/333487 22118400/333487 2048000/30317 3276800/47641 23347200/333487 23756800/333487 24166400/333487 24576000/333487 409600/5467 25395200/333487 3686400/47641 26214400/333487 26624000/333487 2457600/30317 27443200/333487 27852800/333487 28262400/333487 4096000/47641 409600/4697 29491200/333487 29900800/333487 30310400/333487 30720000/333487 31129600/333487 409600/4331 31948800/333487 32358400/333487 32768000/333487 33177600/333487
The offset is getting multiplied by 100 but the division isn't happening


In reply to Strange math issue with Net::SFTP by vendion

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.