简体   繁体   English

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

[英]last-modified field and download file

I have a simple example: 我有一个简单的例子:

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

How to set for download file "test" attributes from file in server ? 如何设置服务器中文件的下载文件“测试”属性? ( create time for file from last modified field ) ? (从上次修改的字段为文件创建时间)?

You get this information by first asking for it with the CURLOPT_FILETIME option to curl_easy_setopt() and after the transfer you extract the time of the document with the CURLINFO_FILETIME option to curl_easy_getinfo() and set it on the local file with utime(). 您可以通过首先使用curl_easy_setopt()的CURLOPT_FILETIME选项来请求获取此信息,并在传输后通过使用带有curl_easy_getinfo()的CURLINFO_FILETIME选项来提取文档的时间,并使用utime()将其设置在本地文件上。

Done! 做完了!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM