cURL / Mailing Lists / curl-library / Single Mail


Re: Resuming failed FTP uploads - example code?

From: <>
Date: Tue, 9 May 2006 23:11:08 -0500

On May 9, 2006, at 10:51 AM, Philip Bock wrote:

> I'm trying to use libcurl to upload large files to a somewhat
> unreliable
> FTP server, and so I need to be able to resume the uploads once the
> connection fails. I'm having some problems getting this going. Is
> there
> any example code somewhere that might help me understand this? I tried
> the search on the mailing list archive page, but didn't find anything
> very helpful.
> My program calls curl_easy_perform() in a loop, setting
> after the first run. My main problem right now is finding out exactly
> how much data was successfully transferred. My CURLOPT_READFUNCTION
> just
> pulls data from a FILE*, so I tried just using continuing from the
> last
> time it was called, but of course that doesn't work because the
> connection failed somewhere during the last block of the transfer, not
> right on the boundary. (By 'block' I mean the data read from one call

I don't have any code, but you want to follow the same logical steps
as you would if using a command-line ftp program. Many servers
support the "SIZE" command. When you issue "size <filename>" it
returns the filesize in bytes. You can then use the "RESTART
<marker>" command where marker specifies the number of bytes into the
file you need to seek.

Make sense? The trick here is to ask the server how many bytes it has
already received in the file so you know at what point to resume.

Received on 2006-05-10