tags:

views:

466

answers:

1

I'm trying to use curl to download a seried of files in the following format:

http://example.com/001.jpg

..

http://example.com/999.jpg

So I used this command:

time curl "http://example.com/[0-9][0-9][0-9].jpg" -o "#1#2#3.gif"

But some of the files don't exist, and that command will create the files on my end but really it will just contain the error page.

I need a way for curl to check if it exists on the remote server before downloading it.

I know wget can do it, but wget seems to take about 5 times longer to run. The command I used to try it in wget is this:

time wget http://example.com/{0..9}{0..9}{0..9}.jpg

+1  A: 

Try -f/--fail option:

(HTTP) Fail silently (no output at all) on server errors. This is mostly done to better enable scripts etc to better deal with failed attempts. In normal cases when a HTTP server fails to deliver a document, it returns an HTML document stating so (which often also describes why and more). This flag will prevent curl from outputting that and return error 22.

This method is not fail-safe and there are occasions where non-successful response codes will slip through, especially when authentication is involved (response codes 401 and 407).

alex vasi
hmm that works although it does give me an output (to the screen) when there's a 404... I don't suppose there's a way to get rid of that too so I will only see something on the screen when it works?
Hintswen
Well, you can stop all output with --silent option. Or just redirect errors using --stderr=filename_or_devnull, another way: "curl ... 2> filename_or_devnull" (http://stackoverflow.com/search?q=[bash]+stderr)
alex vasi