Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include <stdio.h>
00024
00025 #include <curl/curl.h>
00026
00027
00028
00029
00030
00031
00032 struct FtpFile {
00033 const char *filename;
00034 FILE *stream;
00035 };
00036
00037 static size_t my_fwrite(void *buffer, size_t size, size_t nmemb,
00038 void *stream)
00039 {
00040 struct FtpFile *out=(struct FtpFile *)stream;
00041 if(out && !out->stream) {
00042
00043 out->stream=fopen(out->filename, "wb");
00044 if(!out->stream)
00045 return -1;
00046 }
00047 return fwrite(buffer, size, nmemb, out->stream);
00048 }
00049
00050
00051 int main(void)
00052 {
00053 CURL *curl;
00054 CURLcode res;
00055 struct FtpFile ftpfile={
00056 "yourfile.bin",
00057 NULL
00058 };
00059
00060 curl_global_init(CURL_GLOBAL_DEFAULT);
00061
00062 curl = curl_easy_init();
00063 if(curl) {
00064
00065
00066
00067
00068
00069 curl_easy_setopt(curl, CURLOPT_URL,
00070 "ftp://user@server/home/user/file.txt");
00071
00072 curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, my_fwrite);
00073
00074 curl_easy_setopt(curl, CURLOPT_WRITEDATA, &ftpfile);
00075
00076
00077 curl_easy_setopt(curl, CURLOPT_USE_SSL, CURLUSESSL_ALL);
00078
00079
00080 curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
00081
00082 res = curl_easy_perform(curl);
00083
00084
00085 curl_easy_cleanup(curl);
00086
00087 if(CURLE_OK != res) {
00088
00089 fprintf(stderr, "curl told us %d\n", res);
00090 }
00091 }
00092
00093 if(ftpfile.stream)
00094 fclose(ftpfile.stream);
00095
00096 curl_global_cleanup();
00097
00098 return 0;
00099 }