Terminal Tricks: Download with cURL in a Loop Until Completed
Mac OS X — 28 Feb 2007 13:26 — 1108 days ago

Here’s a little terminal command I use to repeatedly attempt to download a file. This is useful if the transfer aborts frequently or if the server is busy:

while ! curl -C - -O 'http://download.parallels.com/GA/Parallels%20Desktop%203186%20Mac%20en.dmg'; do sleep 10; done

As you can see I used this to download Parallels VM, because their servers keep dropping the connection after a while when they’re busy, which often happens when a new release comes out.

The while/do/done loop keeps calling curl, with pauses of 10 seconds. curl will keep returning a failure exit code, which is what keeps the while loop going if inverted with the ! (logical not) operator. The -C - flag tells curl to continue at the last byte position.

Comments
Posted by Caius Durling on 28 Feb 2007 20:50

You can also download it from mirrors, check the forums on parallels for links. I got 700+ kb/s download from them.

Posted by cocaine on 4 Mar 2007 19:41

ha ha,
(so you are the one who is keeping the server busy! ;)

thnx for the tip.

Posted by Wayne - web designer on 17 Mar 2007 18:21

stuff like this makes me glad to have a mac.. on pc I had to write a vb program to do this..

Powered By blojsom