#include <stdio.h>
#include <unistd.h>

#include <curl/curl.h>

#define OOMODE

#ifdef OOMODE
class TestWrapper {
 private:

  CURL* curl;
 public:
  TestWrapper() {
   curl = curl_easy_init();
   curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
  }
  ~TestWrapper() {
   curl_easy_cleanup(curl);
  }
  void GetFile() {
   FILE *ftpfile;
   CURLcode res;
   ftpfile = fopen("readme.txt", "wb");
   curl_easy_setopt(curl, CURLOPT_URL, "ftp://localhost/README");
   curl_easy_setopt(curl, CURLOPT_FILE, ftpfile);
   res = curl_easy_perform(curl);
   fclose(ftpfile);
  }

  void GetList() {
    FILE *ftpls;
    CURLcode res;
    ftpls = fopen("ftpls.txt", "wb");
    curl_easy_setopt(curl, CURLOPT_URL, "ftp://localhost");
    curl_easy_setopt(curl, CURLOPT_FILE, ftpls);
    res = curl_easy_perform(curl);
    fclose(ftpls);
  }
  
};

#else
CURL* curl;
void Init() {
       curl = curl_easy_init();
      curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
}
void End() {
       curl_easy_cleanup(curl);
}
void GetFile() {
      FILE *ftpfile;
      CURLcode res;
      ftpfile = fopen("readme.txt", "wb");
      curl_easy_setopt(curl, CURLOPT_URL, "ftp://localhost/README");
      curl_easy_setopt(curl, CURLOPT_FILE, ftpfile);
      res = curl_easy_perform(curl);
      //fclose(ftpfile);
    }
void GetList() {
      FILE *ftpls;
      CURLcode res;
      ftpls = fopen("ftpls.txt", "wb");
      curl_easy_setopt(curl, CURLOPT_URL, "ftp://localhost");
      curl_easy_setopt(curl, CURLOPT_FILE, ftpls);
      res = curl_easy_perform(curl);
      // fclose(ftpls);
    }
#endif
int main(int argc, char **argv)
{
#ifdef OOMODE
 TestWrapper test;

 test.GetFile();
 test.GetList();
#else
/* Procedural mode   */
 Init();
 GetFile();
 GetList();
 End();
#endif
  return 0;
}
