Resync
[CMakeLuaTailorHgBridge.git] / CMakeLua / Utilities / cmcurl-7.19.0 / docs / examples / ftpgetresp.c
blob16384a19d35eae40da8c2c28a4b0238fe7264327
1 /*****************************************************************************
2 * _ _ ____ _
3 * Project ___| | | | _ \| |
4 * / __| | | | |_) | |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
8 * $Id: ftpgetresp.c,v 1.1.1.1 2008-09-23 16:32:05 hoffman Exp $
9 */
11 #include <stdio.h>
13 #include <curl/curl.h>
14 #include <curl/types.h>
15 #include <curl/easy.h>
18 * Similar to ftpget.c but this also stores the received response-lines
19 * in a separate file using our own callback!
21 * This functionality was introduced in libcurl 7.9.3.
24 static size_t
25 write_response(void *ptr, size_t size, size_t nmemb, void *data)
27 FILE *writehere = (FILE *)data;
28 return fwrite(ptr, size, nmemb, writehere);
31 int main(int argc, char **argv)
33 CURL *curl;
34 CURLcode res;
35 FILE *ftpfile;
36 FILE *respfile;
38 /* local file name to store the file as */
39 ftpfile = fopen("ftp-list", "wb"); /* b is binary, needed on win32 */
41 /* local file name to store the FTP server's response lines in */
42 respfile = fopen("ftp-responses", "wb"); /* b is binary, needed on win32 */
44 curl = curl_easy_init();
45 if(curl) {
46 /* Get a file listing from sunet */
47 curl_easy_setopt(curl, CURLOPT_URL, "ftp://ftp.sunet.se/");
48 curl_easy_setopt(curl, CURLOPT_WRITEDATA, ftpfile);
49 /* If you intend to use this on windows with a libcurl DLL, you must use
50 CURLOPT_WRITEFUNCTION as well */
51 curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, write_response);
52 curl_easy_setopt(curl, CURLOPT_WRITEHEADER, respfile);
53 res = curl_easy_perform(curl);
55 /* always cleanup */
56 curl_easy_cleanup(curl);
59 fclose(ftpfile); /* close the local file */
60 fclose(respfile); /* close the response file */
62 return 0;