最后修改的字段和下载文件

时间:2012-01-17 10:28:38

标签: c curl libcurl

我有一个简单的例子:

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;
}

如何从服务器中的文件设置下载文件“test”属性? (从上次修改的字段创建文件的时间)?

1 个答案:

答案 0 :(得分:0)

您首先通过curl_easy_setopt()的CURLOPT_FILETIME选项询问此信息,然后在转移后使用CURLINFO_FILETIME选项将文档的时间提取到curl_easy_getinfo()并设置它使用utime()在本地文件上。

完成!