/*****************************************************************************
 *                                  _   _ ____  _
 *  Project                     ___| | | |  _ \| |
 *                             / __| | | | |_) | |
 *                            | (__| |_| |  _ <| |___
 *                             \___|\___/|_| \_\_____|
 *
 * $Id: fileupload.c,v 1.2 2004/10/16 13:17:15 giva Exp $
 */
#include "stdafx.h"
#include <stdio.h>
#include <curl/curl.h>
#include <curl/types.h>
#include <curl/easy.h>

#include <sys/stat.h>
#include <fcntl.h>
size_t readFromFile(void *buffer,size_t size,size_t count,FILE *stream)
{
	return fread(buffer,size,count,stream);
}

int main(void) 
{ 

	CURL *curl; 
   CURLcode res; 


   curl = curl_easy_init(); 
   if(curl) { 
     curl_easy_setopt(curl, CURLOPT_URL, "ftps://192.168.100.23/"); 
     res = curl_easy_perform(curl); 


     /* always cleanup */ 
     curl_easy_cleanup(curl); 
	 getchar();
   } 
   return 0; 
} 



int xmain(void)
{
  CURL *curl;
  CURLcode res;
  curl_off_t size;
  struct stat file_info;
  double speed_upload, total_time;
  FILE *fd;

  fd = fopen("C:\\SamplePrograms\\Certificates\\Client\\New Text Document.txt", "rb"); /* open file to upload */
  if(!fd) {

    return 1; /* can't continue */
  }

  stat("C:\\SamplePrograms\\Certificates\\Client\\New Text Document.txt", &file_info); /* to get the file size */

  curl = curl_easy_init();
  if(curl) {
    /* upload to this place */
	  char url[1024];
	  sprintf(url,"ftp://192.168.100.23/New Text Document.txt");
   //   sprintf(url,"ftp://192.168.100.23/New Text Document.txt");
       curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, TRUE);
	  curl_easy_setopt(curl, CURLOPT_URL,url);
	  curl_easy_setopt(curl, CURLOPT_USERPWD,"xxx:xxx");


    curl_easy_setopt(curl,CURLOPT_FTP_SSL ,CURLFTPSSL_ALL);
	curl_easy_setopt(curl,CURLOPT_SSLKEY,"C:\\SamplePrograms\\Certificates\\Client\\client.key.pem");

	curl_easy_setopt(curl , CURLOPT_SSLKEYPASSWD ,"xxx");
    /* tell it to "upload" to the URL */
    curl_easy_setopt(curl, CURLOPT_UPLOAD, 1);

    /* set where to read from (on Windows you need to use READFUNCTION too) */
    curl_easy_setopt(curl, CURLOPT_READDATA, fd);

	curl_easy_setopt(curl, CURLOPT_READFUNCTION ,&readFromFile);

	//curl_easy_setopt(curl , CURLOPT_PORT , 1121);
    /* and give the size of the upload (optional) */
    curl_easy_setopt(curl, CURLOPT_INFILESIZE_LARGE,
                     (curl_off_t)file_info.st_size);

	curl_easy_setopt(curl, CURLOPT_CAPATH , "C:\\SFTP\\OpenSSL\\bin\\PEM\\demoCA" );

//	curl_easy_setopt(curl, 
    /* enable verbose for easier tracing */
    curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);

    res = curl_easy_perform(curl);

    /* now extract transfer info */
    curl_easy_getinfo(curl, CURLINFO_SPEED_UPLOAD, &speed_upload);
    curl_easy_getinfo(curl, CURLINFO_TOTAL_TIME, &total_time);

    fprintf(stderr, "Speed: %.3f bytes/sec during %.3f seconds\n",
            speed_upload, total_time);
int a;
	scanf("%d",&a);
    /* always cleanup */
    curl_easy_cleanup(curl);
  }
  return 0;
}


