|
下面的代码可以实现指定目录下的指定文件上传到一个HTTP 服务器上指定目录下
curl_global_init(CURL_GLOBAL_ALL);
curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, "file_name", CURLFORM_FILE, filepath, CURLFORM_END);
if(httpflag == 0){
curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, "buttom2", CURLFORM_COPYCONTENTS, "UPLOAD", CURLFORM_END);
}else if (httpflag == 1){
curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, "buttom1", CURLFORM_COPYCONTENTS, "UPLOAD", CURLFORM_END);
}
timevalue = conf_get_prop("General", "UploadTimeout");
if (timevalue == NULL) {
TR_MALLOC(timevalue, 10);
TR_STRNCPY(timevalue, DEF_UPLOAD_TIME, 10);
}
curl = curl_easy_init();
if(curl){
//curl_easy_setopt(curl, CURLOPT_HEADER, TRUE);
curl_easy_setopt(curl, CURLOPT_URL, url);
curl_easy_setopt(curl, CURLOPT_USERPWD, userpwd);
curl_easy_setopt(curl, CURLOPT_POST, TRUE);
curl_easy_setopt(curl, CURLOPT_TIMEOUT, atoi(timevalue));
curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost);
res = curl_easy_perform(curl);
}
请问如何用Libcurl实现讲HTTP服务器上指定的文件下载到指定的目录下?急!!!谢谢 |
|