cURL / Mailing Lists / curl-library / Single Mail

curl-library

How can I resume my download?

From: Chronos CC <chronos.cc_at_gmail.com>
Date: Mon, 23 Jan 2012 13:12:57 -0300

Hi all,

I'm trying to create a simple download manager. So a need to implement the
function of resume my incomplete downloads.
Below I show you the peace of code that I tried to implement that function.

struct stat filestatus;
int r = stat("/tmp/file.mpeg", &filestatus);
if(r == 0){
    // size of local file (part)
    long local_offset = (long)filestatus.st_size;
    char remote_offset[50];
    memset(remote_offset, '\0', 50);
    sprintf(remote_offset, "%ld-", local_offset);
    // setting up offset of remote file
    curl_easy_setopt(handler, CURLOPT_RANGE, remote_offset);
    // setting up offset of local file
    curl_easy_setopt(handler, CURLOPT_RESUME_FROM, local_offset);
}

I'm using SFTP protocol. My libraries version are: libssh2-1.3.0 and
curl-7.23.1.
I ever tried to remove curl_easy_setopt(handler, CURLOPT_RANGE,
remote_offset);, but my result was the same. Below I try to explaing my
results.

For example, I want to transfer a file with 100 kB.
I start to download but cancel it before finish. Downloaded just 20 kB.
After, I started to download it again to complete the download (resume
download).
But my problem is that file transfer starts of the beginning. When download
is complete my file ends with 120 kB.

Is it possible to use libcURL to resume download transfer when using SFTP
protocol?

Help me guys, please.

Best Regards,

Antonio Cosme

-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2012-01-23