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;
In reply to Re: FTP with progress bar in Tk?
by zentara
in thread FTP with progress bar in Tk?
by jdtoronto
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |