curl/wget: use content-disposition for the file names
Posted by jpluimers on 2020/04/27
For me, on Windows, curl works better than wget, but on Linux/Mac OS X, curl tends to work better. Some people find wget easier for downloading multiple URLs at the same time. So here the parameter switches for both so they download to the file specified by the Content-Disposition
http header:
curl --remote-name --remote-header-name
wget --content-disposition
My experience is that wget
is better at this, especially when redirects are involved (by adding a [WayBack] --location
parameter to thecurl
command line).
So for instance the first fails, but the second succeeds determining the download to be VSCodeUserSetup-x64-1.27.2.exe
(so curl
keeps the name stable
):
curl.exe --location --remote-name --remote-time --remote-header-name https://vscode-update.azurewebsites.net/latest/win32-x64-user/stable
wget.exe --content-disposition https://vscode-update.azurewebsites.net/latest/win32-x64-user/stable
This takes into account the name after all followed redirects.
Via:
- [WayBack] shell – How do I preserve the remote filename when Downloading a file using curl – Stack Overflow
- [WayBack] How do I save a file using the response header filename with cURL – Stack Overflow
- Often,
--remote-name
gets abbreviated to-O
: [WayBack] Chris Bensen: Bash Scripts Auto Download Dependencies / [WayBack] curl – How To Use: -O
–jeroen
Leave a Reply