Buy commercial curl support from
WolfSSL. We help you work out your issues, debug your libcurl
applications, use the API, port to new platforms, add new features and more.
With a team lead by the curl founder himself.
Re: How can I just get the output name?
- Contemporary messages sorted: [ by date ] [ by thread ] [ by subject ] [ by author ] [ by messages with attachments ]
From: Dan Fandrich via curl-users <curl-users_at_lists.haxx.se>
Date: Tue, 26 Mar 2024 09:10:57 -0700
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
Date: Tue, 26 Mar 2024 09:10:57 -0700
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
-- Unsubscribe: https://lists.haxx.se/mailman/listinfo/curl-users Etiquette: https://curl.se/mail/etiquette.htmlReceived on 2024-03-26