When I went to the ISC here to download BIND, my browser automatically saves the downloaded file correctly. For example, if I click on the Download button for 9.9.4-P2, it pops up a window, and if I click on the "BIND 9.9.4-P2 - tar.gz" button on the right the browser automatically saves the downloaded file as "bind-9.9.4-P2.tar.gz".
However what I'm trying to do is to download it via wget on Linux. So I right click on the "BIND 9.9.4-P2 - tar.gz" button and copied the link which is "https://www.isc.org/downloads/file/bind-9-9-4-p1-tar-gz/?version=tar.gz".
Now when I then issued the following command, it'd save it as 'index.html?version=tar.gz' instead. Now I understand I can give it the -O option and explicitly specify the saved file name but is there a way for it to do this automatically similar to how my browser does it?
wget https://www.isc.org/downloads/file/bind-9-9-4-p1-tar-gz/?version=tar.gz
By default, downloaded file will be saved with the last name mentioned in the URL. To save file with a different name option O can be used. Syntax: wget -O <fileName><URL>
Use wget --content-disposition <url> Explanation: The Content-Disposition header can be used by a server to suggest a filename for a downloaded file. By default, wget uses the last part of the URL as the filename, but you can override this with --content-disposition , which uses the server's suggested name.
How to download a file. To download a file with wget pass the resource your would like to download. The output of the command shows wget connecting to the remote server and the HTTP response. In this case we can see that the file is 758M and is a MIME type of application/x-iso9660-image .
On an HTTP level, the server sends the filename information to the client in the Content-Disposition
header field within the HTTP response:
HTTP/1.1 200 OK
[…]
Content-Disposition: attachment; filename="bind-9.9.4-P2.tar.gz";
See RFC2183 for details on the Content-Disposition
header field.
wget
has experimental support for this feature according to its manpage:
--content-disposition If this is set to on, experimental (not fully-functional) support for "Content-Disposition" headers is enabled. This can currently result in extra round-trips to the server for a "HEAD" request, and is known to suffer from a few bugs, which is why it is not currently enabled by default.
So if you choose to enable it, just specify the --content-disposition
option. (You could also use curl
to do the job instead of wget
, but the question was about wget
.)
You could set the content-disposition parameter to be activated by default.
Just edit the /etc/wgetrc
or ~/.wgetrc
file and append content-disposition = on
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With