Zsh Mailing List Archive
Messages sorted by:
Re: pure zsh implementation of wget
- X-seq: zsh-users 16398
- From: Mikael Magnusson <mikachu@xxxxxxxxx>
- To: Guido van Steen <gvsteen@xxxxxxxxx>
- Subject: Re: pure zsh implementation of wget
- Date: Thu, 22 Sep 2011 23:50:27 +0200
- Cc: zsh-users@xxxxxxx
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=7VY33/fMNaUZAyPHjDfLyu6KyDbJMsO3Uv9kvpQgRCs=; b=OEEWbzekj1wxDOox2W8chLOL88QlCn3fsg0wYUIVEpOGDTHNbQEo6lxAzCFcXWE51V yYkJHFNW1IJ4koAn69FSpRM9rAO3m8eoSKTDStOkcc5z3sqB5IusG2p/5iqM+PJe17Oo S+0goh5VYjoZyBSH20iVakFr5EvGmm5RwytX4=
- In-reply-to: <1316725600.8003.YahooMailClassic@web65605.mail.ac4.yahoo.com>
- List-help: <mailto:email@example.com>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:firstname.lastname@example.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <1316725600.8003.YahooMailClassic@web65605.mail.ac4.yahoo.com>
On 22 September 2011 23:06, Guido van Steen <gvsteen@xxxxxxxxx> wrote:
> I was wondering if someone could point me to a pure zsh implementation of a function/script that downloads files like wget.
> I have been look at this (slightly modified from http://rosettacode.org/wiki/HTTP#Zsh):
> $cat wget.zsh
> #!/usr/bin/env zsh
> zmodload zsh/net/tcp
> ztcp google.com 80
> print -l -u $fd -- 'GET / HTTP/1.1' 'Host: google.com' ''
> while read -u $fd -r -e -t 1; do; :; done
> ztcp -c $fd
> However, when I run this script, I do not receive any files. Neither do I observe any other results. I tried it with other sites, e.g. replacing google.com by localhost, and so on.
> Does someone know what am I missing?
It works for me, but there are a couple of problems. It uses a timeout
of one second, so if your connection is slow it won't do anything, and
it doesn't include the dos newlines i believe you should have in http.
A more severe problem is that it uses read without setting IFS empty
which means it will mangle initial whitespace input. All these issues
(but possibly not others) are solved here (possibly):
ztcp google.com 80
print -l -u $fd -- 'GET / HTTP/1.1'$'\015' 'Host:
www.google.com'$'\015' 'Connection: close'$'\015' $'\015'
while IFS= read -u $fd -r -e; do; :; done
ztcp -c $fd
note that gmail will insert a newline in the print line, so join that
back yourself :) Instead of the while loop you can also just write cat
> BTW, would this work with https as well?
Definitely not :).
Messages sorted by: