Add varaible to the ftpfile structure to learn about your write function, to call and tell libcurl to resume loading from the end of the target file, setting CURLOPT_RESUME_FROM to the number of bytes already loaded:
struct FtpFile { const char *pcInfFil; FILE *pFd; int iAppend; };
Basically, if you want to resume:
curl_easy_setopt(curl, CURLOPT_RESUME_FROM , numberOfBytesToSkip);
If you do not exist yet, or it is not a resumed download, but a new download, be sure to return CURLOPT_RESUME_FROM to 0.
In my_fwrite:
out->stream=fopen(out->filename, out->iAppend ? "ab":"wb");
PS if you need to renew a file larger than a long (2 GB), check out CURLOPT_RESUME_FROM_LARGE and CURL_OFF_T_C ()
In response to a comment requesting additional information on how to find out when a transmission failure:
After you call curl easy, call:
CURLcode curl_easy_getinfo(CURL *curl, CURLINFO info, ... );
Get out of curl context:
CURLINFO_HEADER_SIZE CURLINFO_CONTENT_LENGTH_DOWNLOAD
Add them together and make sure they are equal.
CURLINFO_SIZE_DOWNLOAD
If you do not try to change the context.
And do not forget to use the latest version of curl, it should expire 60 seconds after you do not hear from the FTP server from which it is downloaded.
Motes
source share