size_t getcontentlengthfunc(void* ptr,size_t size,size_t nmemb,void *stream)
int progresscallback(double dltotal,double dlnow,double ultotal,double ulnow)
; //獲取本地檔案大小資訊
if(stat(localpath,&file_info)==0)
//追加方式開啟檔案,實現斷點續傳
f=fopen(localpath,"ab+");
if(f==null)
r=curl_easy_setopt(curlhandle,curlopt_url,remotepath);
//連線超時設定
r=curl_easy_setopt(curlhandle,curlopt_connecttimeout,timeout);
//設定頭處理函式
r=curl_easy_setopt(curlhandle,curlopt_headerfunction,getcontentlengthfunc);
r=curl_easy_setopt(curlhandle,curlopt_headerdata,&filesize);
//設定斷點續傳
r=curl_easy_setopt(curlhandle,curlopt_resume_from,use_resume?local_file_len:0);
r=curl_easy_setopt(curlhandle,curlopt_writefunction,writefunc);
r=curl_easy_setopt(curlhandle,curlopt_writedata,f);
r=curl_easy_setopt(curlhandle,curlopt_noprogress,0l);
curl_easy_setopt(curlhandle,curlopt_progressfunction,progresscallback);
r=curl_easy_setopt(curlhandle,curlopt_verbose,1l);
r=curl_easy_perform(curlhandle);
fclose(f);
if(r==curle_ok)
return 1;
else if(r==curle_ftp_couldnt_use_rest)
f=fopen(localpath,"ab+");
if(f==null)
curl_easy_cleanup(curlhandle);
curlhandle=curl_easy_init();
curl_easy_setopt(curlhandle,curlopt_url,remotepath);
//連線超時設定
curl_easy_setopt(curlhandle,curlopt_connecttimeout,timeout);
//設定頭處理函式
curl_easy_setopt(curlhandle,curlopt_headerfunction,getcontentlengthfunc);
curl_easy_setopt(curlhandle,curlopt_headerdata,&filesize);
//設定斷點續傳
curl_easy_setopt(curlhandle,curlopt_resume_from,use_resume?local_file_len:0);
curl_easy_setopt(curlhandle,curlopt_writefunction,writefunc);
curl_easy_setopt(curlhandle,curlopt_writedata,f);
curl_easy_setopt(curlhandle,curlopt_noprogress,0l);
curl_easy_setopt(curlhandle,curlopt_progressfunction,progresscallback);
curl_easy_setopt(curlhandle,curlopt_verbose,1l);
r=curl_easy_perform(curlhandle);
fclose(f);
}else
return 0;
int main()
{ curl *curldwn=null;
curl_global_init(curl_global_all);
curldwn=curl_easy_init();
//1-超時時間
//download(curldwn,"","c:\\22.pdf",1);
download(curldwn,"","c:\\21.pdf",1);
curl_easy_cleanup(curldwn);
curl_global_cleanup();
getchar();
return 0;
HTTP 斷點續傳
客戶端請求域 range 格式如下例子 第乙個500位元組 位元組偏移量0 499,包括0和499 range bytes 0 499 第二個500位元組 位元組偏移量500 999,包括500和999 range bytes 500 999 最後500位元組 位元組偏移量9500 9999,包括9...
IOS斷點續傳
asihttprequest可以實現斷點續傳。網上有一些介紹類似使用 request setallowresumeforfiledownloads yes 不過,通過asihttprequest的非同步請求以及delegate還是可以實現斷點續傳的。本文還是以grails編寫斷點續傳伺服器端為例。非...
linux斷點續傳
在linux伺服器上經常要用scp傳輸大檔案,可能由於網路等原因出現間接性中斷,導致傳輸一半的檔案突然中斷。其實scp是可以續傳的,它需要rsync以及它的ssh協議 舉例如下 rsync p rsh ssh home.tar 192.168.205.34 home home.tar,再輸出密碼後,...