Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (1)
As of 2024-04-25 00:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found