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 /* Check for binutils 2.19.1 from ftp.gnu.org's FTP site. */
32 char ftpurl[] = "ftp://ftp.gnu.org/gnu/binutils/binutils-2.19.1.tar.bz2";
35 const time_t filetime;
36 const double filesize;
37 const char *filename = strrchr(ftpurl, '/') + 1;
39 curl_global_init(CURL_GLOBAL_DEFAULT);
41 curl = curl_easy_init();
43 curl_easy_setopt(curl, CURLOPT_URL, ftpurl);
44 /* No download if the file */
45 curl_easy_setopt(curl, CURLOPT_NOBODY, 1L);
46 /* Ask for filetime */
47 curl_easy_setopt(curl, CURLOPT_FILETIME, 1L);
48 /* No header output: TODO 14.1 http-style HEAD output for ftp */
49 curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, throw_away);
50 curl_easy_setopt(curl, CURLOPT_HEADER, 0L);
51 /* Switch on full protocol/debug output */
52 /* curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L); */
54 res = curl_easy_perform(curl);
57 /* http://curl.haxx.se/libcurl/c/curl_easy_getinfo.html */
58 res = curl_easy_getinfo(curl, CURLINFO_FILETIME, &filetime);
59 if((CURLE_OK == res) && filetime)
60 printf("filetime %s: %s", filename, ctime(&filetime));
61 res = curl_easy_getinfo(curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &filesize);
62 if((CURLE_OK == res) && filesize)
63 printf("filesize %s: %0.0f bytes\n", filename, filesize);
66 fprintf(stderr, "curl told us %d\n", res);
70 curl_easy_cleanup(curl);
73 curl_global_cleanup();