Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include <stdio.h>
00027 #include <curl/curl.h>
00028 #include <sys/stat.h>
00029 #include <fcntl.h>
00030
00031 int main(void)
00032 {
00033 CURL *curl;
00034 CURLcode res;
00035 struct stat file_info;
00036 double speed_upload, total_time;
00037 FILE *fd;
00038
00039 fd = fopen("debugit", "rb");
00040 if(!fd)
00041 return 1;
00042
00043
00044 if(fstat(fileno(fd), &file_info) != 0)
00045 return 1;
00046
00047 curl = curl_easy_init();
00048 if(curl) {
00049
00050 curl_easy_setopt(curl, CURLOPT_URL,
00051 "file:///home/dast/src/curl/debug/new");
00052
00053
00054 curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L);
00055
00056
00057 curl_easy_setopt(curl, CURLOPT_READDATA, fd);
00058
00059
00060 curl_easy_setopt(curl, CURLOPT_INFILESIZE_LARGE,
00061 (curl_off_t)file_info.st_size);
00062
00063
00064 curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
00065
00066 res = curl_easy_perform(curl);
00067
00068 if(res != CURLE_OK) {
00069 fprintf(stderr, "curl_easy_perform() failed: %s\n",
00070 curl_easy_strerror(res));
00071
00072 }
00073 else {
00074
00075 curl_easy_getinfo(curl, CURLINFO_SPEED_UPLOAD, &speed_upload);
00076 curl_easy_getinfo(curl, CURLINFO_TOTAL_TIME, &total_time);
00077
00078 fprintf(stderr, "Speed: %.3f bytes/sec during %.3f seconds\n",
00079 speed_upload, total_time);
00080
00081 }
00082
00083 curl_easy_cleanup(curl);
00084 }
00085 fclose(fd);
00086 return 0;
00087 }