Re: How can I just get the output name?
ToddAndMargo via curl-users <[email protected]>
| Newsgroups | gmane.comp.web.curl.general |
|---|---|
| Message-ID | <[email protected]> |
On 3/26/24 09:10, Dan Fandrich via curl-users wrote:
> On Tue, Mar 26, 2024 at 07:18:21AM -0700, ToddAndMargo via curl-users wrote:
>> On 3/24/24 05:41, ToddAndMargo via curl-users wrote:
>>> Firefox CliGet gives me this when I click on a particular
>>> download link:
>>>
>>> curl --header 'Host: dl.duosecurity.com'
>>> ...
>>> 'https://dl.duosecurity.com/duo-win-login-latest.exe'
>>> --output 'duo-win-login-4.3.0.exe'
>>>
>>> All I want is the "duo-win-login-4.3.0.exe" text.
>>> Using cURL, is there a way to get?
>
> This will do it:
>
> curl -sI -o /dev/null --write-out '%header{content-disposition}\n' \
> https://dl.duosecurity.com/duo-win-login-latest.exe | \
> sed -e 's/^.*="//' -e 's/".*$//'
>
> This requests only the headers from the site and writes out just the
> Content-Disposition: header, then strips off everything that's outside
> quotation marks. You'd want a more robust header parser if you want to work it
> to work reliably with any file name on any site, but it's likely good enough
> for this one URL. You'll need a curl version at least 7.83.0 to get the %header
> feature.
>
> Dan
Hi Dan,
Awesome!
$ curl -sI -o /dev/null --write-out '%header{content-disposition}\n'
https://dl.duosecurity.com/duo-win-login-latest.exe
attachment; filename="duo-win-login-4.3.0.exe"
$ curl -sI -o /dev/null --write-out '%header{content-disposition}\n'
https://dl.duosecurity.com/duo-win-login-latest.exe | sed -e 's/^.*="//'
-e 's/".*$//'
duo-win-login-4.3.0.exe
Thank you!
-T
--
Unsubscribe: https://lists.haxx.se/mailman/listinfo/curl-users
Etiquette: https://curl.se/mail/etiquette.html