cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: Is there a canonical callback implementation for 'remote thingy exists'?

From: Dan Fandrich <dan_at_coneharvesters.com>
Date: Fri, 1 Oct 2010 14:55:02 -0700

On Fri, Oct 01, 2010 at 02:34:33PM -0700, John Utz wrote:
> My limited understanding of libcurl leads me to conclude that to create a
> 'remote file or directory exists' function i want to create a 'do nothing'
> callback.
>
> The docs indicate that it should return a number different then what is getting
> passed into it as a filesize for the remote file and this will cause the
> curl_easy_perform() to abort.
>
> However, i am a bit unsure as to what it should return, it seems like it should
> be any negative number.

That will work fine.

> I also want to avoid downloading anything in this circumstance, because i have
> no interest in the content of the files or directories, i just want to get the
> existence answer as frugally as possible.
>
> What do the rest of you do?

Returning a negative number will abort the download, but depending on the
protocol there may be a more efficient way of doing it. If you set
CURLOPT_NOBODY, then libcurl will attempt to perform a transfer that returns
metadata about the URL but not the data itself. For HTTP, it will do a HEAD
instead of a GET, and for ftp, it will return just the date and size of the
file. If the URL doesn't exist, you'll get an error. You could also get an
error from some servers or URLs where this isn't supported, so be careful,
but this will avoid the overhead of setting up a large data transfer that
will immediately be canceled by the app.

>>> Dan
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2010-10-01