2011-03-10 05:48:02 -05:00
|
|
|
/***************************************************************************
|
2007-07-06 16:14:03 -04:00
|
|
|
* _ _ ____ _
|
|
|
|
* Project ___| | | | _ \| |
|
|
|
|
* / __| | | | |_) | |
|
|
|
|
* | (__| |_| | _ <| |___
|
2002-01-08 03:25:44 -05:00
|
|
|
* \___|\___/|_| \_\_____|
|
|
|
|
*
|
2016-02-11 03:42:38 -05:00
|
|
|
* Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
|
2011-03-10 05:48:02 -05:00
|
|
|
*
|
|
|
|
* This software is licensed as described in the file COPYING, which
|
|
|
|
* you should have received as part of this distribution. The terms
|
2016-02-02 18:19:02 -05:00
|
|
|
* are also available at https://curl.haxx.se/docs/copyright.html.
|
2011-03-10 05:48:02 -05:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
***************************************************************************/
|
2002-01-08 03:25:44 -05:00
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include <curl/curl.h>
|
|
|
|
|
2015-06-18 05:38:54 -04:00
|
|
|
/* <DESC>
|
|
|
|
* Similar to ftpget.c but also stores the received response-lines
|
2002-01-08 03:25:44 -05:00
|
|
|
* in a separate file using our own callback!
|
2015-06-18 05:38:54 -04:00
|
|
|
* </DESC>
|
2002-01-08 03:25:44 -05:00
|
|
|
*/
|
2007-07-16 17:22:12 -04:00
|
|
|
static size_t
|
2002-01-08 03:25:44 -05:00
|
|
|
write_response(void *ptr, size_t size, size_t nmemb, void *data)
|
|
|
|
{
|
|
|
|
FILE *writehere = (FILE *)data;
|
|
|
|
return fwrite(ptr, size, nmemb, writehere);
|
|
|
|
}
|
|
|
|
|
2016-02-11 03:42:38 -05:00
|
|
|
#define FTPBODY "ftp-list"
|
|
|
|
#define FTPHEADERS "ftp-responses"
|
|
|
|
|
2010-12-17 17:34:26 -05:00
|
|
|
int main(void)
|
2002-01-08 03:25:44 -05:00
|
|
|
{
|
|
|
|
CURL *curl;
|
|
|
|
CURLcode res;
|
|
|
|
FILE *ftpfile;
|
|
|
|
FILE *respfile;
|
2007-07-06 16:14:03 -04:00
|
|
|
|
2002-01-08 03:25:44 -05:00
|
|
|
/* local file name to store the file as */
|
2016-02-11 03:42:38 -05:00
|
|
|
ftpfile = fopen(FTPBODY, "wb"); /* b is binary, needed on win32 */
|
2002-01-08 03:25:44 -05:00
|
|
|
|
|
|
|
/* local file name to store the FTP server's response lines in */
|
2016-02-11 03:42:38 -05:00
|
|
|
respfile = fopen(FTPHEADERS, "wb"); /* b is binary, needed on win32 */
|
2002-01-08 03:25:44 -05:00
|
|
|
|
|
|
|
curl = curl_easy_init();
|
|
|
|
if(curl) {
|
|
|
|
/* Get a file listing from sunet */
|
2010-10-05 09:00:19 -04:00
|
|
|
curl_easy_setopt(curl, CURLOPT_URL, "ftp://ftp.example.com/");
|
2003-12-08 09:13:19 -05:00
|
|
|
curl_easy_setopt(curl, CURLOPT_WRITEDATA, ftpfile);
|
2007-07-06 16:14:03 -04:00
|
|
|
/* If you intend to use this on windows with a libcurl DLL, you must use
|
|
|
|
CURLOPT_WRITEFUNCTION as well */
|
2002-01-08 03:25:44 -05:00
|
|
|
curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, write_response);
|
2014-07-05 10:59:12 -04:00
|
|
|
curl_easy_setopt(curl, CURLOPT_HEADERDATA, respfile);
|
2002-01-08 03:25:44 -05:00
|
|
|
res = curl_easy_perform(curl);
|
2012-07-04 11:03:52 -04:00
|
|
|
/* Check for errors */
|
|
|
|
if(res != CURLE_OK)
|
|
|
|
fprintf(stderr, "curl_easy_perform() failed: %s\n",
|
|
|
|
curl_easy_strerror(res));
|
2002-01-08 03:25:44 -05:00
|
|
|
|
|
|
|
/* always cleanup */
|
|
|
|
curl_easy_cleanup(curl);
|
|
|
|
}
|
|
|
|
|
|
|
|
fclose(ftpfile); /* close the local file */
|
|
|
|
fclose(respfile); /* close the response file */
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|