From 053bf49bd24db8fe8f4556291100f9b99bb2c4a0 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 27 Mar 2001 09:00:18 +0000 Subject: Added ftpget.c just to show that it is exactly as easy to get FTP files --- docs/examples/ftpget.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 docs/examples/ftpget.c (limited to 'docs/examples/ftpget.c') diff --git a/docs/examples/ftpget.c b/docs/examples/ftpget.c new file mode 100644 index 000000000..bdf854521 --- /dev/null +++ b/docs/examples/ftpget.c @@ -0,0 +1,44 @@ +/***************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * $Id$ + */ + +#include + +#include +#include +#include + +/* to make this work under windows, use the win32-functions from the + win32socket.c file as well */ + +int main(int argc, char **argv) +{ + CURL *curl; + CURLcode res; + FILE *ftpfile; + + /* local file name to store the file as */ + ftpfile = fopen("curl.tar.gz", "wb"); /* b is binary for win */ + + curl = curl_easy_init(); + if(curl) { + /* Get curl 7.7 from sunet.se's FTP site: */ + curl_easy_setopt(curl, CURLOPT_URL, + "ftp://ftp.sunet.se/pub/www/utilities/curl/curl-7.7.tar.gz"); + curl_easy_setopt(curl, CURLOPT_FILE, ftpfile); + res = curl_easy_perform(curl); + + /* always cleanup */ + curl_easy_cleanup(curl); + } + + fclose(ftpfile); /* close the local file */ + + return 0; +} -- cgit v1.2.1 From 0b1197936c488950041cc54db9db9af1d82ea0b8 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 8 Jan 2002 13:05:44 +0000 Subject: I made the write callback create the file the first time it gets called so that it won't create an empty file if the remote file doesn't exist --- docs/examples/ftpget.c | 61 +++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 50 insertions(+), 11 deletions(-) (limited to 'docs/examples/ftpget.c') diff --git a/docs/examples/ftpget.c b/docs/examples/ftpget.c index bdf854521..6d728c6ec 100644 --- a/docs/examples/ftpget.c +++ b/docs/examples/ftpget.c @@ -14,31 +14,70 @@ #include #include -/* to make this work under windows, use the win32-functions from the - win32socket.c file as well */ +/* + * This is an example showing how to get a single file from an FTP server. + * It delays the actual destination file creation until the first write + * callback so that it won't create an empty file in case the remote file + * doesn't exist or something else fails. + */ + +struct FtpFile { + char *filename; + FILE *stream; +}; + +int my_fwrite(void *buffer, size_t size, size_t nmemb, void *stream) +{ + struct FtpFile *out=(struct FtpFile *)stream; + if(out && !out->stream) { + /* open file for writing */ + out->stream=fopen(out->filename, "wb"); + if(!out->stream) + return -1; /* failure, can't open file to write */ + } + return fwrite(buffer, size, nmemb, out->stream); +} + -int main(int argc, char **argv) +int main(void) { CURL *curl; CURLcode res; - FILE *ftpfile; - - /* local file name to store the file as */ - ftpfile = fopen("curl.tar.gz", "wb"); /* b is binary for win */ + struct FtpFile ftpfile={ + "curl.tar.gz", /* name to store the file as if succesful */ + NULL + }; + curl_global_init(CURL_GLOBAL_DEFAULT); + curl = curl_easy_init(); if(curl) { - /* Get curl 7.7 from sunet.se's FTP site: */ + /* Get curl 7.9.2 from sunet.se's FTP site: */ curl_easy_setopt(curl, CURLOPT_URL, - "ftp://ftp.sunet.se/pub/www/utilities/curl/curl-7.7.tar.gz"); - curl_easy_setopt(curl, CURLOPT_FILE, ftpfile); + "ftp://ftp.sunet.se/pub/www/utilities/curl/curl-7.9.2.tar.gz"); + /* Define our callback to get called when there's data to be written */ + curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, my_fwrite); + /* Set a pointer to our struct to pass to the callback */ + curl_easy_setopt(curl, CURLOPT_FILE, &ftpfile); + + /* Switch on full protocol/debug output */ + curl_easy_setopt(curl, CURLOPT_VERBOSE, TRUE); + res = curl_easy_perform(curl); /* always cleanup */ curl_easy_cleanup(curl); + + if(CURLE_OK != res) { + /* we failed */ + fprintf(stderr, "curl told us %d\n", res); + } } - fclose(ftpfile); /* close the local file */ + if(ftpfile.stream) + fclose(ftpfile.stream); /* close the local file */ + + curl_global_cleanup(); 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/ftpget.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docs/examples/ftpget.c') diff --git a/docs/examples/ftpget.c b/docs/examples/ftpget.c index 6d728c6ec..2c2275fa5 100644 --- a/docs/examples/ftpget.c +++ b/docs/examples/ftpget.c @@ -58,7 +58,7 @@ int main(void) /* Define our callback to get called when there's data to be written */ curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, my_fwrite); /* Set a pointer to our struct to pass to the callback */ - curl_easy_setopt(curl, CURLOPT_FILE, &ftpfile); + curl_easy_setopt(curl, CURLOPT_WRITEDATA, &ftpfile); /* Switch on full protocol/debug output */ curl_easy_setopt(curl, CURLOPT_VERBOSE, TRUE); -- cgit v1.2.1 From d736ac51c047119c8d82df9f18b127cbcecc86c6 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Mon, 23 Aug 2004 14:22:52 +0000 Subject: stripped trailing whitespace --- docs/examples/ftpget.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'docs/examples/ftpget.c') diff --git a/docs/examples/ftpget.c b/docs/examples/ftpget.c index 2c2275fa5..0274b7f69 100644 --- a/docs/examples/ftpget.c +++ b/docs/examples/ftpget.c @@ -1,8 +1,8 @@ /***************************************************************************** - * _ _ ____ _ - * Project ___| | | | _ \| | - * / __| | | | |_) | | - * | (__| |_| | _ <| |___ + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * * $Id$ @@ -49,10 +49,14 @@ int main(void) }; curl_global_init(CURL_GLOBAL_DEFAULT); - + curl = curl_easy_init(); if(curl) { - /* Get curl 7.9.2 from sunet.se's FTP site: */ + /* + * Get curl 7.9.2 from sunet.se's FTP site. curl 7.9.2 is most likely not + * present there by the time you read this, so you'd better replace the + * URL with one that works! + */ curl_easy_setopt(curl, CURLOPT_URL, "ftp://ftp.sunet.se/pub/www/utilities/curl/curl-7.9.2.tar.gz"); /* Define our callback to get called when there's data to be written */ -- cgit v1.2.1 From 49ce3e5160a9576e797bf87cef012b09d1c54ecb Mon Sep 17 00:00:00 2001 From: Dan Fandrich Date: Thu, 12 Jul 2007 21:11:10 +0000 Subject: Fixed some compile warnings and errors and improved portability in the examples. Removed ftp3rdparty.c since libcurl doesn't support 3rd party FTP transfers any longer. --- docs/examples/ftpget.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'docs/examples/ftpget.c') diff --git a/docs/examples/ftpget.c b/docs/examples/ftpget.c index 0274b7f69..4e3fc8fc3 100644 --- a/docs/examples/ftpget.c +++ b/docs/examples/ftpget.c @@ -22,7 +22,7 @@ */ struct FtpFile { - char *filename; + const char *filename; FILE *stream; }; @@ -65,7 +65,7 @@ int main(void) curl_easy_setopt(curl, CURLOPT_WRITEDATA, &ftpfile); /* Switch on full protocol/debug output */ - curl_easy_setopt(curl, CURLOPT_VERBOSE, TRUE); + curl_easy_setopt(curl, CURLOPT_VERBOSE, 1); 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/ftpget.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docs/examples/ftpget.c') diff --git a/docs/examples/ftpget.c b/docs/examples/ftpget.c index 4e3fc8fc3..42e70bd57 100644 --- a/docs/examples/ftpget.c +++ b/docs/examples/ftpget.c @@ -26,7 +26,7 @@ struct FtpFile { FILE *stream; }; -int my_fwrite(void *buffer, size_t size, size_t nmemb, void *stream) +static int my_fwrite(void *buffer, size_t size, size_t nmemb, void *stream) { struct FtpFile *out=(struct FtpFile *)stream; if(out && !out->stream) { -- cgit v1.2.1 From b12fef3f3137bc606d283a2e527dd9050edf2b12 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 27 Feb 2008 09:06:15 +0000 Subject: Michal Marek's cleanup of how curl_easy_setopt() is used in examples and test code. Thanks to his curl_easy_setopt() typechecker work... --- docs/examples/ftpget.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docs/examples/ftpget.c') diff --git a/docs/examples/ftpget.c b/docs/examples/ftpget.c index 42e70bd57..155e79cb7 100644 --- a/docs/examples/ftpget.c +++ b/docs/examples/ftpget.c @@ -26,7 +26,7 @@ struct FtpFile { FILE *stream; }; -static int my_fwrite(void *buffer, size_t size, size_t nmemb, void *stream) +static size_t my_fwrite(void *buffer, size_t size, size_t nmemb, void *stream) { struct FtpFile *out=(struct FtpFile *)stream; if(out && !out->stream) { -- cgit v1.2.1 From e664cd5826d43930fcc5b5dbaedbec94af33184b Mon Sep 17 00:00:00 2001 From: Dan Fandrich Date: Thu, 22 May 2008 21:20:07 +0000 Subject: Fixed a surprising number of example programs that were passing int arguments to curl_easy_setopt instead of long. --- docs/examples/ftpget.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docs/examples/ftpget.c') diff --git a/docs/examples/ftpget.c b/docs/examples/ftpget.c index 155e79cb7..179fd6129 100644 --- a/docs/examples/ftpget.c +++ b/docs/examples/ftpget.c @@ -65,7 +65,7 @@ int main(void) curl_easy_setopt(curl, CURLOPT_WRITEDATA, &ftpfile); /* Switch on full protocol/debug output */ - curl_easy_setopt(curl, CURLOPT_VERBOSE, 1); + curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L); res = curl_easy_perform(curl); -- 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/ftpget.c | 1 - 1 file changed, 1 deletion(-) (limited to 'docs/examples/ftpget.c') diff --git a/docs/examples/ftpget.c b/docs/examples/ftpget.c index 179fd6129..78727e7ef 100644 --- a/docs/examples/ftpget.c +++ b/docs/examples/ftpget.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/ftpget.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'docs/examples/ftpget.c') diff --git a/docs/examples/ftpget.c b/docs/examples/ftpget.c index 78727e7ef..3c3888a20 100644 --- a/docs/examples/ftpget.c +++ b/docs/examples/ftpget.c @@ -52,12 +52,10 @@ int main(void) curl = curl_easy_init(); if(curl) { /* - * Get curl 7.9.2 from sunet.se's FTP site. curl 7.9.2 is most likely not - * present there by the time you read this, so you'd better replace the - * URL with one that works! + * You better replace the URL with one that works! */ curl_easy_setopt(curl, CURLOPT_URL, - "ftp://ftp.sunet.se/pub/www/utilities/curl/curl-7.9.2.tar.gz"); + "ftp://ftp.example.com/pub/www/utilities/curl/curl-7.9.2.tar.gz"); /* Define our callback to get called when there's data to be written */ curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, my_fwrite); /* Set a pointer to our struct to pass to the callback */ -- 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/ftpget.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'docs/examples/ftpget.c') diff --git a/docs/examples/ftpget.c b/docs/examples/ftpget.c index 3c3888a20..7b5e0d7cf 100644 --- a/docs/examples/ftpget.c +++ b/docs/examples/ftpget.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/ftpget.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'docs/examples/ftpget.c') diff --git a/docs/examples/ftpget.c b/docs/examples/ftpget.c index 7b5e0d7cf..bcb42bb30 100644 --- a/docs/examples/ftpget.c +++ b/docs/examples/ftpget.c @@ -22,8 +22,6 @@ #include #include -#include -#include /* * This is an example showing how to get a single file from an FTP server. -- cgit v1.2.1