in reply to Capture wget progress bar
Presumably the REASON you want to do this is so you can report how the download is going. If this is what you want to do you will find it easier just to do it with a socket. Say you want something via http
#!/usr/bin/perl use IO::Socket::INET; my $debug = 1; my $get = 'http://www.mysite.com/index.html'; my ( $domain, $stuff ) = $get =~ m!http://([^/]+)(.*)$!; $sock = IO::Socket::INET->new( PeerAddr => $domain, PeerPort => 80, Proto => 'tcp'); die "No socket" unless $sock; print "Got sock\n"; my ( $content, $buffer ); print $sock "HEAD $get HTTP/1.0\015\012\015\012"; $content .= $buffer while ( read ( $sock, $buffer, 1024 ) ); print $content if $debug; die $content unless $content =~ m/200 OK/; my ($content_length) = $content =~ m/^Content-Length:\s*(\d+)/m; print "Content-Length: $content_length\n" if $debug; $content = ''; $sock = IO::Socket::INET->new( PeerAddr => $domain, PeerPort => 80, Proto => 'tcp'); binmode $sock; print $sock "GET $get HTTP/1.0\015\012\015\012"; my $found_crlf = 0; while ( read ( $sock, $buffer, 1024 ) ) { $content .= $buffer; # we need to chop off the header at the first CRLFCRLF if ( ! $found_crlf and index($content, "\015\012\015\012") > 0 ) { $content = substr $content, (index $content, "\015\012\015\012 +") + 4; $found_crlf = 1; } printf "Got %.2f%\n", ( 100* length($content)/$content_length ) if +$debug; } print $content if $debug; __DATA__ Got sock HTTP/1.1 200 OK Date: Sat, 15 Mar 2003 13:07:35 GMT Server: Apache/1.3.26 (Unix) PHP/4.1.2 Last-Modified: Fri, 17 Jan 2003 01:08:19 GMT ETag: "1d0f53-a36-3e275783" Accept-Ranges: bytes Content-Length: 2614 Connection: close Content-Type: text/html X-Pad: avoid browser bug Content-Length: 2614 Got 28.27% Got 67.44% Got 100.00% <html> <head> [blah]
tachyon
s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Capture wget progress bar
by rendler (Pilgrim) on Mar 15, 2003 at 13:25 UTC | |
by tachyon (Chancellor) on Mar 16, 2003 at 06:20 UTC | |
by rendler (Pilgrim) on Mar 16, 2003 at 08:25 UTC | |
by tachyon (Chancellor) on Mar 16, 2003 at 09:15 UTC |