質問

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
役に立ちましたか?

解決

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

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top