2012-01-17 104 views
0

我有一個簡單的例子:最後修改場和下載文件

include <curl/curl.h> 
char tmp[] = "/var/tmp/tmp"; 
char fullpath[] = "/var/tmp/test"; 
FILE* fp; 
CURL* curl; 
char bufferError[CURL_ERROR_SIZE]; 
CURLcode result; 

int main() { 
    curl = curl_easy_init(); 
    fp = fopen(tmp, "wb"); 
    char url[] = "http://10.100.1.5/promorolik/Skoro_Shrek_4_obrez.mp4"; 
    curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, bufferError); 
    curl_easy_setopt(curl, CURLOPT_URL, url); 
    curl_easy_setopt(curl, CURLOPT_HEADER, 0); 
    curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1); 
    curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1); 
    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, NULL); 
    curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp); 
    curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0); 
    result = curl_easy_perform(curl); 
    curl_easy_cleanup(curl); 
    fclose(fp); 
    rename(tmp, fullpath); 
    return 0; 
} 

如何下載文件「測試」設置從文件屬性中的服務器? (從最後修改字段創建文件的時間)?

回答

0

通過首先詢問curl_easy_setopt()的CURLOPT_FILETIME選項獲取此信息,並在傳輸完成後將包含CURLINFO_FILETIME選項的文檔的時間提取到curl_easy_getinfo()並使用utime()將其設置在本地文件上)。

完成!