Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "getFiles.h"
- #include <cstdio>
- #include <boost/filesystem.hpp>
- size_t getFiles::my_fwrite(void *buffer, size_t size, size_t nmemb, void *stream) {
- struct FtpFile *out=(struct FtpFile *)stream;
- if(out && !out->stream) {
- /* open file for writing */
- /* if (out->destination.c_str() != NULL) { // Boost needs fix!!!!! Doesn't create folder as supposed to!
- boost::filesystem::create_directories(out->destination);
- } */
- out->stream=fopen(out->filename.c_str(), "wb");
- if(!out->stream)
- return -1; /* failure, can't open file to write */
- }
- return fwrite(buffer, size, nmemb, out->stream);
- }
- void getFiles::run() {
- if(curl) {
- /*
- * You better replace the URL with one that works!
- */
- curl_easy_setopt(curl, CURLOPT_URL,
- URL.c_str());
- curl_easy_setopt(curl,CURLOPT_FTP_CREATE_MISSING_DIRS, 1L);
- /* Define our callback to get called when there's data to be written */
- curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, my_fwrite);
- /* Set a pointer to our struct to pass to the callback */
- curl_easy_setopt(curl, CURLOPT_WRITEDATA, &ftpfile);
- /* Switch on full protocol/debug output */
- curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
- res = curl_easy_perform(curl);
- /* always cleanup */
- curl_easy_cleanup(curl);
- if(CURLE_OK != res) {
- /* we failed */
- fprintf(stderr, "curl told us %d\n", res);
- }
- }
- if(ftpfile.stream)
- fclose(ftpfile.stream); /* close the local file */
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement