doom3-gpl
Doom 3 GPL source release
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ftpgetresp.c
Go to the documentation of this file.
1 /*****************************************************************************
2  * _ _ ____ _
3  * Project ___| | | | _ \| |
4  * / __| | | | |_) | |
5  * | (__| |_| | _ <| |___
6  * \___|\___/|_| \_\_____|
7  *
8  * $Id: ftpgetresp.c,v 1.2 2003/12/08 14:13:19 bagder Exp $
9  */
10 
11 #include <stdio.h>
12 
13 #include <curl/curl.h>
14 #include <curl/types.h>
15 #include <curl/easy.h>
16 
17 /*
18  * Similar to ftpget.c but this also stores the received response-lines
19  * in a separate file using our own callback!
20  *
21  * This functionality was introduced in libcurl 7.9.3.
22  */
23 
24 size_t
25 write_response(void *ptr, size_t size, size_t nmemb, void *data)
26 {
27  FILE *writehere = (FILE *)data;
28  return fwrite(ptr, size, nmemb, writehere);
29 }
30 
31 int main(int argc, char **argv)
32 {
33  CURL *curl;
34  CURLcode res;
35  FILE *ftpfile;
36  FILE *respfile;
37 
38  /* local file name to store the file as */
39  ftpfile = fopen("ftp-list", "wb"); /* b is binary, needed on win32 */
40 
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 */
43 
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  curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, write_response);
50  curl_easy_setopt(curl, CURLOPT_WRITEHEADER, respfile);
51  res = curl_easy_perform(curl);
52 
53  /* always cleanup */
54  curl_easy_cleanup(curl);
55  }
56 
57  fclose(ftpfile); /* close the local file */
58  fclose(respfile); /* close the response file */
59 
60  return 0;
61 }
size_t write_response(void *ptr, size_t size, size_t nmemb, void *data)
Definition: ftpgetresp.c:25
CURLcode curl_easy_perform(CURL *curl)
Definition: easy.c:260
CURLcode
Definition: curl.h:209
CURLcode curl_easy_setopt(CURL *curl, CURLoption option,...)
Definition: easy.c:217
GLsizei GLsizei GLenum GLenum const GLvoid * data
Definition: glext.h:2853
int main(int argc, char **argv)
Definition: ftpgetresp.c:31
GLsizeiptr size
Definition: glext.h:3112
void CURL
Definition: types.h:25
GLuint res
Definition: glext.h:5385
void curl_easy_cleanup(CURL *curl)
Definition: easy.c:288
#define CURLOPT_WRITEDATA
Definition: curl.h:805
size_t fwrite(const void *, size_t, size_t, FILE *)
CURL * curl_easy_init(void)
Definition: easy.c:195