wget downloads corrupt JPEG file

I'm trying to use wget to automatically download a wallpaper. Here is the command:

wget

However, if I try to open the resulting picture, it seems to say it has a bad magic number. By running file 1600.jpg, I get 1600.jpg: GIF image data, version 89a, 1 x 1. If I open it as a GIF it doesn't work either. It's only 37 bytes too.

It works perfectly fine if I view or download it through Firefox.

Any ideas?

1 Answer

I think it's some kind of protection against direct downloads, nothing wrong with wget (the server is sending you a transparent 1x1 GIF image).

You can circumvent this by using wget with the -U flag, adding the user agent string of your browser, eg.:

wget -U "Mozilla/5.0 (X11; U; Linux i686; en-US) AppleWebKit/534.17 (KHTML, like Gecko) Ubuntu/11.04 Chromium/11.0.654.0 Chrome/11.0.654.0 Safari/534.17"

BUT: You should first ask the owner of that website if it's ok to download the content this way. There has to be a reason why the usual wget approach is blocked (maybe it's intentional, maybe it's just misconfiguration).

2

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like