2011-03-10 13:48:02 +03:00
|
|
|
/***************************************************************************
|
2007-07-07 00:14:03 +04:00
|
|
|
* _ _ ____ _
|
|
|
|
* Project ___| | | | _ \| |
|
|
|
|
* / __| | | | |_) | |
|
|
|
|
* | (__| |_| | _ <| |___
|
2002-01-08 11:25:44 +03:00
|
|
|
* \___|\___/|_| \_\_____|
|
|
|
|
*
|
2011-03-10 13:48:02 +03:00
|
|
|
* Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, 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.
|
|
|
|
*
|
|
|
|
***************************************************************************/
|
2002-01-08 11:25:44 +03:00
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include <curl/curl.h>
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2007-07-17 01:22:12 +04:00
|
|
|
static size_t
|
2002-01-08 11:25:44 +03:00
|
|
|
write_response(void *ptr, size_t size, size_t nmemb, void *data)
|
|
|
|
{
|
|
|
|
FILE *writehere = (FILE *)data;
|
|
|
|
return fwrite(ptr, size, nmemb, writehere);
|
|
|
|
}
|
|
|
|
|
2010-12-18 01:34:26 +03:00
|
|
|
int main(void)
|
2002-01-08 11:25:44 +03:00
|
|
|
{
|
|
|
|
CURL *curl;
|
|
|
|
CURLcode res;
|
|
|
|
FILE *ftpfile;
|
|
|
|
FILE *respfile;
|
2007-07-07 00:14:03 +04:00
|
|
|
|
2002-01-08 11:25:44 +03:00
|
|
|
/* 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 */
|
2010-10-05 17:00:19 +04:00
|
|
|
curl_easy_setopt(curl, CURLOPT_URL, "ftp://ftp.example.com/");
|
2003-12-08 17:13:19 +03:00
|
|
|
curl_easy_setopt(curl, CURLOPT_WRITEDATA, ftpfile);
|
2007-07-07 00: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 11:25:44 +03:00
|
|
|
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;
|
|
|
|
}
|