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 #include <stdio.h>
00023 #include <string.h>
00024
00025 #include <curl/curl.h>
00026
00027
00028
00029
00030
00031
00032 static size_t throw_away(void *ptr, size_t size, size_t nmemb, void *data)
00033 {
00034 (void)ptr;
00035 (void)data;
00036
00037
00038 return (size_t)(size * nmemb);
00039 }
00040
00041 int main(void)
00042 {
00043 char ftpurl[] = "ftp://ftp.example.com/gnu/binutils/binutils-2.19.1.tar.bz2";
00044 CURL *curl;
00045 CURLcode res;
00046 long filetime = -1;
00047 double filesize = 0.0;
00048 const char *filename = strrchr(ftpurl, '/') + 1;
00049
00050 curl_global_init(CURL_GLOBAL_DEFAULT);
00051
00052 curl = curl_easy_init();
00053 if(curl) {
00054 curl_easy_setopt(curl, CURLOPT_URL, ftpurl);
00055
00056 curl_easy_setopt(curl, CURLOPT_NOBODY, 1L);
00057
00058 curl_easy_setopt(curl, CURLOPT_FILETIME, 1L);
00059
00060 curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, throw_away);
00061 curl_easy_setopt(curl, CURLOPT_HEADER, 0L);
00062
00063
00064
00065 res = curl_easy_perform(curl);
00066
00067 if(CURLE_OK == res) {
00068
00069 res = curl_easy_getinfo(curl, CURLINFO_FILETIME, &filetime);
00070 if((CURLE_OK == res) && (filetime >= 0)) {
00071 time_t file_time = (time_t)filetime;
00072 printf("filetime %s: %s", filename, ctime(&file_time));
00073 }
00074 res = curl_easy_getinfo(curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD,
00075 &filesize);
00076 if((CURLE_OK == res) && (filesize>0.0))
00077 printf("filesize %s: %0.0f bytes\n", filename, filesize);
00078 }
00079 else {
00080
00081 fprintf(stderr, "curl told us %d\n", res);
00082 }
00083
00084
00085 curl_easy_cleanup(curl);
00086 }
00087
00088 curl_global_cleanup();
00089
00090 return 0;
00091 }