cURL / Mailing Lists / curl-library / Single Mail


Re: Resuming failed FTP uploads - example code?

From: Philip Bock <>
Date: Wed, 10 May 2006 08:49:11 -0600 (MDT)

On 5/9/2006, "Dan Fandrich" <> wrote:

Thank you for your response.

>Instead, on your next connection to the server request the length of
>the file that made it to the server, i.e. the equivalent of a
>'curl -I ftp://host/file'. I'm not sure the best way to do this--probably a
>NOBODY request and look for a 'Content-Length:' header. That's the value
>you'll need to pass into fseek().

I've been trying to figure this out. What I'm doing right now, based on
reading src/main.c and lib/ftp.c in the curl distribution, is this:

curl_easy_setopt(easyhandle, CURLOPT_URL, "ftp://host/file");
curl_easy_setopt(easyhandle, CURLOPT_USERPWD, "1:2");
curl_easy_setopt(easyhandle, CURLOPT_NOBODY, TRUE);
curl_easy_setopt(easyhandle, CURLOPT_HEADER, TRUE);
curl_easy_setopt(easyhandle, CURLOPT_FILETIME, TRUE);
curl_easy_setopt(easyhandle, CURLOPT_FTPPORT, "-");
curl_easy_setopt(easyhandle, CURLOPT_VERBOSE, TRUE);
r = curl_easy_perform(easyhandle);
curl_easy_getinfo(easyhandle, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &len);
printf("remote file size: %g\n", len);

I can see the result of the SIZE command in the debug output, and I can
see the Content-length: header in the header output, however, len is
always set to 0. Could it be that I'm asking curl_easy_getinfo() for
the wrong thing? None of the other options looks right. I suppose I can
parse the headers manually, if I have to.

Thanks, Philip Bock
Received on 2006-05-10