1 /*****************************************************************************
3 * Project ___| | | | _ \| |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
13 #include <curl/curl.h>
14 #include <curl/types.h>
15 #include <curl/easy.h>
18 * This is an example showing how to check a single file's size and mtime
22 static size_t throw_away(void *ptr, size_t size, size_t nmemb, void *data)
24 /* we are not interested in the headers itself,
25 so we only return the size we would have saved ... */
26 return (size_t)(size * nmemb);
31 char ftpurl[] = "ftp://ftp.example.com/gnu/binutils/binutils-2.19.1.tar.bz2";
34 const time_t filetime;
35 const double filesize;
36 const char *filename = strrchr(ftpurl, '/') + 1;
38 curl_global_init(CURL_GLOBAL_DEFAULT);
40 curl = curl_easy_init();
42 curl_easy_setopt(curl, CURLOPT_URL, ftpurl);
43 /* No download if the file */
44 curl_easy_setopt(curl, CURLOPT_NOBODY, 1L);
45 /* Ask for filetime */
46 curl_easy_setopt(curl, CURLOPT_FILETIME, 1L);
47 /* No header output: TODO 14.1 http-style HEAD output for ftp */
48 curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, throw_away);
49 curl_easy_setopt(curl, CURLOPT_HEADER, 0L);
50 /* Switch on full protocol/debug output */
51 /* curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L); */
53 res = curl_easy_perform(curl);
56 /* http://curl.haxx.se/libcurl/c/curl_easy_getinfo.html */
57 res = curl_easy_getinfo(curl, CURLINFO_FILETIME, &filetime);
58 if((CURLE_OK == res) && filetime)
59 printf("filetime %s: %s", filename, ctime(&filetime));
60 res = curl_easy_getinfo(curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &filesize);
61 if((CURLE_OK == res) && filesize)
62 printf("filesize %s: %0.0f bytes\n", filename, filesize);
65 fprintf(stderr, "curl told us %d\n", res);
69 curl_easy_cleanup(curl);
72 curl_global_cleanup();