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 #include <stdio.h>
00023
00024 #include <curl/curl.h>
00025
00026
00027
00028
00029
00030
00031 struct FtpFile {
00032 const char *filename;
00033 FILE *stream;
00034 };
00035
00036 static size_t my_fwrite(void *buffer, size_t size, size_t nmemb, void *stream)
00037 {
00038 struct FtpFile *out=(struct FtpFile *)stream;
00039 if(out && !out->stream) {
00040
00041 out->stream=fopen(out->filename, "wb");
00042 if(!out->stream)
00043 return -1;
00044 }
00045 return fwrite(buffer, size, nmemb, out->stream);
00046 }
00047
00048
00049 int main(void)
00050 {
00051 CURL *curl;
00052 CURLcode res;
00053 struct FtpFile ftpfile={
00054 "curl.tar.gz",
00055 NULL
00056 };
00057
00058 curl_global_init(CURL_GLOBAL_DEFAULT);
00059
00060 curl = curl_easy_init();
00061 if(curl) {
00062
00063
00064
00065 curl_easy_setopt(curl, CURLOPT_URL,
00066 "ftp://ftp.example.com/curl/curl-7.9.2.tar.gz");
00067
00068 curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, my_fwrite);
00069
00070 curl_easy_setopt(curl, CURLOPT_WRITEDATA, &ftpfile);
00071
00072
00073 curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
00074
00075 res = curl_easy_perform(curl);
00076
00077
00078 curl_easy_cleanup(curl);
00079
00080 if(CURLE_OK != res) {
00081
00082 fprintf(stderr, "curl told us %d\n", res);
00083 }
00084 }
00085
00086 if(ftpfile.stream)
00087 fclose(ftpfile.stream);
00088
00089 curl_global_cleanup();
00090
00091 return 0;
00092 }