Ubuntu 15.10 GNOME Terminal

Wget and the user agent option

Wget is a command-line utility for downloading files.

The official description on its man page on my Linux distribution says that it is “free utility for non-interactive download of files from the Web”, and that it “supports HTTP, HTTPS, and FTP protocols, as well as retrieval through HTTP proxies.”

It especially comes in handy when I need to download an image from another Web resource. I’ve never had any problem using it until just today when I got a 403 Forbidden error message. The edited output is shown in this code block:

Years ago I read somewhere that that usually indicates an Apache server that has been configured via .htaccess to deny file downloads or something of that nature. Since the image file was something I really needed for an article, I decided to poke around the documentation and search the Internet for clues. That effort drew my attention to one of the tools options – the --user-agent or -U option.

Here’s what the man page has to say about it:

The HTTP protocol allows the clients to identify themselves using a “User-Agent” header field. This enables distinguishing the WWW software, usually for statistical purposes or for tracing of protocol violations. Wget normally identifies as Wget/version, version being the current version number of Wget.

However, some sites have been known to impose the policy of tailoring the output according to the “User-Agent”-supplied information. While this is not such a bad idea in theory, it has been abused by servers denying information to clients other than (historically) Netscape or, more frequently, Microsoft Internet Explorer. This option allows you to change the “User-Agent” line issued by Wget. Use of this option is discouraged, unless you really know what you are doing.

Specifying empty user agent with –user-agent=”” instructs Wget not to send the “User-Agent” header in HTTP requests.

With that, I decided to retry the download by specifying an empty user agent as shown in this code block:

That was all it took. There might be other situations where the --user-agent or -U option likely fail, but in this specific case, that was what the doctor ordered.

Please share:
Tags: No tags

Add a Comment

Your email address will not be published. Required fields are marked *