You can also use wget or libcurl in a thread or a piped open,and get progress out of it. With wget it's a bit harder because you have to filter it's output, and do regexes to get the percentage done. I just posted a method on comp.lang.perl.tk. Do a search at http://groups.google.com for "non-blocking downloads with indicator" and you will get one you can modify.

Or libcurl has an easy way to get download progress. Here is an example and you can fork-exec to run it, or use a thread to run it non-blocking and get your percentage back to your tk app. I just posted a way to do this here->Tk-with-worker-threads You can put the code below into the worker thread code, and pass a url to it through the shared hash

#!/usr/bin/perl use warnings; use strict; use WWW::Curl::easy; # Read URL to get my $url = "http://zentara.zentara.net/~zentara/cgi-bin/avi-out.cgi"; # Init the curl session my $curl = WWW::Curl::easy->new(); if ($curl == 0) {print "not ok $!\n "} $curl->setopt(CURLOPT_NOPROGRESS, 0); $curl->setopt(CURLOPT_FOLLOWLOCATION, 1); sub prog_callb{ my ($clientp,$dltotal,$dlnow,$ultotal,$ulnow)=@_; my $percentage = ($dlnow/$dltotal)*100; print STDERR "dltotal: $dltotal, dlnow: $dlnow\t", sprintf("%.0f",$pe +rcentage),"% complete\n"; return 0; } $curl->setopt(CURLOPT_PROGRESSFUNCTION, \&prog_callb); open HEAD, ">$0-head.out"; $curl->setopt(CURLOPT_WRITEHEADER, *HEAD); open BODY, ">$0-body.out"; $curl->setopt(CURLOPT_FILE,*BODY); $curl->setopt(CURLOPT_URL, $url); # Add some additional headers to the http-request: #my @myheaders; #$myheaders[0] = "Server: www"; #$myheaders[1] = "User-Agent: Perl interface for libcURL"; #$curl->setopt(CURLOPT_HTTPHEADER, \@myheaders); # Go get it my $retcode=$curl->perform(); if ($retcode == 0) { my $bytes = $curl->getinfo(CURLINFO_SIZE_DOWNLOAD); print STDERR "$bytes bytes read "; my $realurl=$curl->getinfo(CURLINFO_EFFECTIVE_URL); my $httpcode=$curl->getinfo(CURLINFO_HTTP_CODE); print STDERR "effective fetched url (http code: $httpcode) was: $u +rl "; } else { # We can acces the error message in $errbuf here print STDERR "$retcode / ".$curl->errbuf."\n"; } exit;

I'm not really a human, but I play one on earth. flash japh

In reply to Re: FTP with progress bar in Tk? by zentara
in thread FTP with progress bar in Tk? by jdtoronto

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.