From aec7358ca47d39d1967c528bc5f3b75f67f6d4be Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 8 Jan 2002 08:25:44 +0000 Subject: 7.9.3 pre-release commit --- docs/examples/ftpgetresp.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 docs/examples/ftpgetresp.c (limited to 'docs/examples/ftpgetresp.c') diff --git a/docs/examples/ftpgetresp.c b/docs/examples/ftpgetresp.c new file mode 100644 index 000000000..eb56e19d2 --- /dev/null +++ b/docs/examples/ftpgetresp.c @@ -0,0 +1,61 @@ +/***************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * $Id$ + */ + +#include + +#include +#include +#include + +/* + * Similar to ftpget.c but this also stores the received response-lines + * in a separate file using our own callback! + * + * This functionality was introduced in libcurl 7.9.3. + */ + +size_t +write_response(void *ptr, size_t size, size_t nmemb, void *data) +{ + FILE *writehere = (FILE *)data; + return fwrite(ptr, size, nmemb, writehere); +} + +int main(int argc, char **argv) +{ + CURL *curl; + CURLcode res; + FILE *ftpfile; + FILE *respfile; + + /* local file name to store the file as */ + ftpfile = fopen("ftp-list", "wb"); /* b is binary, needed on win32 */ + + /* local file name to store the FTP server's response lines in */ + respfile = fopen("ftp-responses", "wb"); /* b is binary, needed on win32 */ + + curl = curl_easy_init(); + if(curl) { + /* Get a file listing from sunet */ + curl_easy_setopt(curl, CURLOPT_URL, "ftp://ftp.sunet.se/"); + curl_easy_setopt(curl, CURLOPT_FILE, ftpfile); + curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, write_response); + curl_easy_setopt(curl, CURLOPT_WRITEHEADER, respfile); + res = curl_easy_perform(curl); + + /* always cleanup */ + curl_easy_cleanup(curl); + } + + fclose(ftpfile); /* close the local file */ + fclose(respfile); /* close the response file */ + + return 0; +} -- cgit v1.2.1 From f68219ddaab9dab05a195a6fd126b4edb5ecccdc Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Mon, 8 Dec 2003 14:13:19 +0000 Subject: use the newer option names --- docs/examples/ftpgetresp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docs/examples/ftpgetresp.c') diff --git a/docs/examples/ftpgetresp.c b/docs/examples/ftpgetresp.c index eb56e19d2..82b1d36a7 100644 --- a/docs/examples/ftpgetresp.c +++ b/docs/examples/ftpgetresp.c @@ -45,7 +45,7 @@ int main(int argc, char **argv) if(curl) { /* Get a file listing from sunet */ curl_easy_setopt(curl, CURLOPT_URL, "ftp://ftp.sunet.se/"); - curl_easy_setopt(curl, CURLOPT_FILE, ftpfile); + curl_easy_setopt(curl, CURLOPT_WRITEDATA, ftpfile); curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, write_response); curl_easy_setopt(curl, CURLOPT_WRITEHEADER, respfile); res = curl_easy_perform(curl); -- cgit v1.2.1 From e2bac4fe6f290af6408570f3ed918e4672866c31 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Fri, 6 Jul 2007 20:14:03 +0000 Subject: add note about windows and dlls with CURLOPT_WRITEDATA --- docs/examples/ftpgetresp.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'docs/examples/ftpgetresp.c') diff --git a/docs/examples/ftpgetresp.c b/docs/examples/ftpgetresp.c index 82b1d36a7..cf61ded02 100644 --- a/docs/examples/ftpgetresp.c +++ b/docs/examples/ftpgetresp.c @@ -1,8 +1,8 @@ /***************************************************************************** - * _ _ ____ _ - * Project ___| | | | _ \| | - * / __| | | | |_) | | - * | (__| |_| | _ <| |___ + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * * $Id$ @@ -34,7 +34,7 @@ int main(int argc, char **argv) CURLcode res; FILE *ftpfile; FILE *respfile; - + /* local file name to store the file as */ ftpfile = fopen("ftp-list", "wb"); /* b is binary, needed on win32 */ @@ -46,6 +46,8 @@ int main(int argc, char **argv) /* Get a file listing from sunet */ curl_easy_setopt(curl, CURLOPT_URL, "ftp://ftp.sunet.se/"); curl_easy_setopt(curl, CURLOPT_WRITEDATA, ftpfile); + /* If you intend to use this on windows with a libcurl DLL, you must use + CURLOPT_WRITEFUNCTION as well */ curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, write_response); curl_easy_setopt(curl, CURLOPT_WRITEHEADER, respfile); res = curl_easy_perform(curl); -- cgit v1.2.1 From 4706a9334149f656eef9b5e8888da1ead23b0941 Mon Sep 17 00:00:00 2001 From: Dan Fandrich Date: Mon, 16 Jul 2007 21:22:12 +0000 Subject: Fixed some more simple compile warnings in the examples. --- docs/examples/ftpgetresp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docs/examples/ftpgetresp.c') diff --git a/docs/examples/ftpgetresp.c b/docs/examples/ftpgetresp.c index cf61ded02..31c1f424f 100644 --- a/docs/examples/ftpgetresp.c +++ b/docs/examples/ftpgetresp.c @@ -21,7 +21,7 @@ * This functionality was introduced in libcurl 7.9.3. */ -size_t +static size_t write_response(void *ptr, size_t size, size_t nmemb, void *data) { FILE *writehere = (FILE *)data; -- cgit v1.2.1 From 2309b4e330b96bc2e1f8e36b6184015e59544037 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 24 Mar 2010 11:02:54 +0100 Subject: remove the CVSish $Id$ lines --- docs/examples/ftpgetresp.c | 1 - 1 file changed, 1 deletion(-) (limited to 'docs/examples/ftpgetresp.c') diff --git a/docs/examples/ftpgetresp.c b/docs/examples/ftpgetresp.c index 31c1f424f..8d837f36f 100644 --- a/docs/examples/ftpgetresp.c +++ b/docs/examples/ftpgetresp.c @@ -5,7 +5,6 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * $Id$ */ #include -- cgit v1.2.1 From 18e7b52e8e95f7204d8ef7ff0f0ff0043afe45a9 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 5 Oct 2010 15:00:19 +0200 Subject: examples: use example.com in example URLs --- docs/examples/ftpgetresp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docs/examples/ftpgetresp.c') diff --git a/docs/examples/ftpgetresp.c b/docs/examples/ftpgetresp.c index 8d837f36f..2122c4f68 100644 --- a/docs/examples/ftpgetresp.c +++ b/docs/examples/ftpgetresp.c @@ -43,7 +43,7 @@ int main(int argc, char **argv) curl = curl_easy_init(); if(curl) { /* Get a file listing from sunet */ - curl_easy_setopt(curl, CURLOPT_URL, "ftp://ftp.sunet.se/"); + curl_easy_setopt(curl, CURLOPT_URL, "ftp://ftp.example.com/"); curl_easy_setopt(curl, CURLOPT_WRITEDATA, ftpfile); /* If you intend to use this on windows with a libcurl DLL, you must use CURLOPT_WRITEFUNCTION as well */ -- cgit v1.2.1 From 9583b4af9057c9e35ec3dd3270d4c4813b5f7aaa Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Fri, 17 Dec 2010 23:34:26 +0100 Subject: examples: fix compiler warnings --- docs/examples/ftpgetresp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docs/examples/ftpgetresp.c') diff --git a/docs/examples/ftpgetresp.c b/docs/examples/ftpgetresp.c index 2122c4f68..c78832f3c 100644 --- a/docs/examples/ftpgetresp.c +++ b/docs/examples/ftpgetresp.c @@ -27,7 +27,7 @@ write_response(void *ptr, size_t size, size_t nmemb, void *data) return fwrite(ptr, size, nmemb, writehere); } -int main(int argc, char **argv) +int main(void) { CURL *curl; CURLcode res; -- cgit v1.2.1 From 1aeb635cdd296c16acb375a4a83a78f13166ccab Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Thu, 10 Mar 2011 11:48:02 +0100 Subject: sources: update source headers All C and H files now (should) feature the proper project curl source code header, which includes basic info, a copyright statement and some basic disclaimers. --- docs/examples/ftpgetresp.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'docs/examples/ftpgetresp.c') diff --git a/docs/examples/ftpgetresp.c b/docs/examples/ftpgetresp.c index c78832f3c..ea882a00f 100644 --- a/docs/examples/ftpgetresp.c +++ b/docs/examples/ftpgetresp.c @@ -1,12 +1,24 @@ -/***************************************************************************** +/*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - */ - + * Copyright (C) 1998 - 2011, Daniel Stenberg, , et al. + * + * This software is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at http://curl.haxx.se/docs/copyright.html. + * + * You may opt to use, copy, modify, merge, publish, distribute and/or sell + * copies of the Software, and permit persons to whom the Software is + * furnished to do so, under the terms of the COPYING file. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ***************************************************************************/ #include #include -- cgit v1.2.1 From ac28971aa61d28e5dd54888e34e958d1c742b461 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 28 Jun 2011 19:08:51 +0200 Subject: examples: cleanup curl includes Only is needed typically and curl/types.h has been removed --- docs/examples/ftpgetresp.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'docs/examples/ftpgetresp.c') diff --git a/docs/examples/ftpgetresp.c b/docs/examples/ftpgetresp.c index ea882a00f..29290a31d 100644 --- a/docs/examples/ftpgetresp.c +++ b/docs/examples/ftpgetresp.c @@ -22,8 +22,6 @@ #include #include -#include -#include /* * Similar to ftpget.c but this also stores the received response-lines -- cgit v1.2.1 From a3dbbcfd2ac7ab8f597e26e76935726279d3fa0c Mon Sep 17 00:00:00 2001 From: Guenter Knauf Date: Wed, 4 Jul 2012 17:03:52 +0200 Subject: Added error checking for samples. --- docs/examples/ftpgetresp.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'docs/examples/ftpgetresp.c') diff --git a/docs/examples/ftpgetresp.c b/docs/examples/ftpgetresp.c index 29290a31d..db96a3a13 100644 --- a/docs/examples/ftpgetresp.c +++ b/docs/examples/ftpgetresp.c @@ -60,6 +60,10 @@ int main(void) curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, write_response); curl_easy_setopt(curl, CURLOPT_WRITEHEADER, respfile); res = curl_easy_perform(curl); + /* Check for errors */ + if(res != CURLE_OK) + fprintf(stderr, "curl_easy_perform() failed: %s\n", + curl_easy_strerror(res)); /* always cleanup */ curl_easy_cleanup(curl); -- cgit v1.2.1