Nebu
Nebu

Reputation: 1793

Curl download file from command line

I use the following syntax to download images from the web and store them on my local server:

curl.exe --insecure --o "[local file path]" "[url of file]"

In most cases this works just fine. However in some cases curl creates an empty image instead of the actual image. For example the following command generates an empty image, and not the actual image from the url.

curl.exe --insecure --o "c:\testimage.jpg" "http://www.tristar.eu/cdn/EEFB2494D7B08A43156799AFC3B0FAF7D9C5A2E014A3FA6F/1059034.jpg"

I have no idea why this is happening and i would very much like to fix this behaviour and save the actual image.

Upvotes: 1

Views: 3030

Answers (1)

Daniel Stenberg
Daniel Stenberg

Reputation: 58164

curl -I [the URL]

returns...

HTTP/1.1 302 Found
Location: http://cdn.tristar.eu/generated/EEFB2494D7B08A43156799AFC3B0FAF7D9C5A2E014A3FA6F/1059034.jpg
...

So you need to ask curl to follow the redirect to get the final contents. Add -Lto the command line!

Upvotes: 2

Related Questions