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: Check remote file exist with libcurl
- Contemporary messages sorted: [ by date ] [ by thread ] [ by subject ] [ by author ] [ by messages with attachments ]
From: Dan Fandrich via curl-users <curl-users_at_cool.haxx.se>
Date: Sun, 17 Jan 2021 08:14:57 -0800
On Sun, Jan 17, 2021 at 10:20:00AM +0100, Sztrepka Pál via curl-users wrote:
> I want to write a function that checks to see if a remote file (prot. http)
> exists.
> ( Do not download the file content, only check! )
> I have tried several curl options but so far have failed.
> (only header option, max file size option, range option... not work)
>
> For example:
> curl -IH http:www.example.org/bigfile.xml
The -H option here doesn't many any sense. Just curl -I <url> should be enough.
Adding --fail should make it easier to detect the result in most cases.
> The problem: For a large file, this unfortunately takes a long time to get
> the result back.
> But, i don't understand why.
curl just sends the command. If it takes a long time to get a result, it's
likely a server problem. -I should only return a very short result, so a delay
could mean the server has to generate a large output dynamically, then throw it
all away and return just the headers. This is the only way to get the
Content-Length: for a dynamic URL, for example. Also, some servers don't
support -I on some URLs and you'll a false result in those cases.
Dan
-----------------------------------------------------------
Unsubscribe: https://cool.haxx.se/list/listinfo/curl-users
Etiquette: https://curl.haxx.se/mail/etiquette.html
Received on 2021-01-17
Date: Sun, 17 Jan 2021 08:14:57 -0800
On Sun, Jan 17, 2021 at 10:20:00AM +0100, Sztrepka Pál via curl-users wrote:
> I want to write a function that checks to see if a remote file (prot. http)
> exists.
> ( Do not download the file content, only check! )
> I have tried several curl options but so far have failed.
> (only header option, max file size option, range option... not work)
>
> For example:
> curl -IH http:www.example.org/bigfile.xml
The -H option here doesn't many any sense. Just curl -I <url> should be enough.
Adding --fail should make it easier to detect the result in most cases.
> The problem: For a large file, this unfortunately takes a long time to get
> the result back.
> But, i don't understand why.
curl just sends the command. If it takes a long time to get a result, it's
likely a server problem. -I should only return a very short result, so a delay
could mean the server has to generate a large output dynamically, then throw it
all away and return just the headers. This is the only way to get the
Content-Length: for a dynamic URL, for example. Also, some servers don't
support -I on some URLs and you'll a false result in those cases.
Dan
-----------------------------------------------------------
Unsubscribe: https://cool.haxx.se/list/listinfo/curl-users
Etiquette: https://curl.haxx.se/mail/etiquette.html
Received on 2021-01-17