1 /***************************************************************************
3 * Project ___| | | | _ \| |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
8 * Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al.
10 * This software is licensed as described in the file COPYING, which
11 * you should have received as part of this distribution. The terms
12 * are also available at http://curl.haxx.se/docs/copyright.html.
14 * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15 * copies of the Software, and permit persons to whom the Software is
16 * furnished to do so, under the terms of the COPYING file.
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
21 ***************************************************************************/
25 #include <curl/curl.h>
28 * Get a single file from an FTPS server.
37 static size_t my_fwrite(void *buffer, size_t size, size_t nmemb,
40 struct FtpFile *out=(struct FtpFile *)stream;
41 if(out && !out->stream) {
42 /* open file for writing */
43 out->stream=fopen(out->filename, "wb");
45 return -1; /* failure, can't open file to write */
47 return fwrite(buffer, size, nmemb, out->stream);
55 struct FtpFile ftpfile={
56 "yourfile.bin", /* name to store the file as if successful */
60 curl_global_init(CURL_GLOBAL_DEFAULT);
62 curl = curl_easy_init();
65 * You better replace the URL with one that works! Note that we use an
66 * FTP:// URL with standard explicit FTPS. You can also do FTPS:// URLs if
67 * you want to do the rarer kind of transfers: implicit.
69 curl_easy_setopt(curl, CURLOPT_URL,
70 "ftp://user@server/home/user/file.txt");
71 /* Define our callback to get called when there's data to be written */
72 curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, my_fwrite);
73 /* Set a pointer to our struct to pass to the callback */
74 curl_easy_setopt(curl, CURLOPT_WRITEDATA, &ftpfile);
76 /* We activate SSL and we require it for both control and data */
77 curl_easy_setopt(curl, CURLOPT_USE_SSL, CURLUSESSL_ALL);
79 /* Switch on full protocol/debug output */
80 curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
82 res = curl_easy_perform(curl);
85 curl_easy_cleanup(curl);
89 fprintf(stderr, "curl told us %d\n", res);
94 fclose(ftpfile.stream); /* close the local file */
96 curl_global_cleanup();