cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: Réf. : Ftps

From: Lars Nilsson <chamaeleon_at_gmail.com>
Date: Wed, 14 Sep 2005 10:25:32 -0400

Would now be a good time to change your password? Seeing how you
posted the CURLOPT_USERPWD for the world to see.

Lars Nilsson

On 9/14/05, Luiz Rafael Culik Guimaraes <luiz_at_xharbour.com.br> wrote:
> Ralph, Phil
>
> >That number (577736507914191548) is in excess of 500 petabytes. Are you
> >really trying to ship >that much data??
> No. the filesize is actualy 471040 bytes
>
> >maybe it can help if you send your "modified ftpupload sample" !
> Sure. here the code
>
> /*****************************************************************************
> * _ _ ____ _
> * Project ___| | | | _ \| |
> * / __| | | | |_) | |
> * | (__| |_| | _ <| |___
> * \___|\___/|_| \_\_____|
> *
> * $Id: ftpupload.c,v 1.7 2005/01/20 14:24:56 bagder Exp $
> */
>
> #include <stdio.h>
>
> #include <curl/curl.h>
> #include <sys/types.h>
> #include <sys/stat.h>
> #include <fcntl.h>
>
> /*
> * This example shows an FTP upload, with a rename of the file just after
> * a successful upload.
> *
> * Example based on source code provided by Erick Nuwendam. Thanks!
> */
>
> #define LOCAL_FILE "/tmp/uploadthis.txt"
> #define UPLOAD_FILE_AS "while-uploading.txt"
> #define REMOTE_URL "ftp://localhost/" UPLOAD_FILE_AS
> #define RENAME_FILE_TO "renamed-and-fine.txt"
> #define TRUE 1
> int main(int argc, char **argv)
> {
> CURL *curl;
> CURLcode res;
> FILE *ftpfile;
> FILE * hd_src ;
> int hd ;
> struct stat file_info;
> const char *pCertFile = "/etc/ssl/certs/rafael.pem";
> const char *pCACertFile="/etc/ftpd/ca.crt";
> const char *pKeyName = "/etc/ssl/certs/rafael.key.unsecure";
>
> struct curl_slist *headerlist=NULL;
> // char buf_1 [] = "RNFR " UPLOAD_FILE_AS;
> // char buf_2 [] = "RNTO " RENAME_FILE_TO;
>
> /* get the file size of the local file */
> hd = open(LOCAL_FILE, O_RDONLY) ;
> fstat(hd, &file_info);
> close(hd) ;
>
> /* get a FILE * of the same file, could also be made with
> fdopen() from the previous descriptor, but hey this is just
> an example! */
> hd_src = fopen(LOCAL_FILE, "rb");
>
> /* In windows, this will init the winsock stuff */
> curl_global_init(CURL_GLOBAL_ALL);
>
> /* get a curl handle */
> curl = curl_easy_init();
> if(curl) {
> /* build a list of commands to pass to libcurl */
> // headerlist = curl_slist_append(headerlist, buf_1);
> // headerlist = curl_slist_append(headerlist, buf_2);
> curl_easy_setopt(curl, CURLOPT_FTP_USE_EPSV, 0);
> curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
> curl_easy_setopt(curl, CURLOPT_FTP_SSL, 1);
> curl_easy_setopt(curl, CURLOPT_USERPWD, "rafael:kl6qaxv9");
> // curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0);
> // curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0);
> curl_easy_setopt(curl,CURLOPT_FTPSSLAUTH,CURLFTPAUTH_TLS);
> curl_easy_setopt(curl,CURLOPT_SSLCERTTYPE,"PEM");
>
> /* set the cert for client authentication */
> curl_easy_setopt(curl,CURLOPT_SSLCERT,pCertFile);
>
> /* sorry, for engine we must set the passphrase
> (if the key has one...) */
> // if (pPassphrase)
> // curl_easy_setopt(curl,CURLOPT_SSLKEYPASSWD,pPassphrase);
>
> /* if we use a key stored in a crypto engine,
> we must set the key type to "ENG" */
> curl_easy_setopt(curl,CURLOPT_SSLKEYTYPE,"PEM");
>
> // /* set the private key (file or ID in engine) */
> curl_easy_setopt(curl,CURLOPT_SSLKEY,pKeyName);
>
> /* set the file with the certs vaildating the server */
> curl_easy_setopt(curl,CURLOPT_CAINFO,pCACertFile);
> /* enable uploading */
> curl_easy_setopt(curl, CURLOPT_UPLOAD, TRUE) ;
>
> /* specify target */
> curl_easy_setopt(curl,CURLOPT_URL, REMOTE_URL);
>
> /* pass in that last of FTP commands to run after the transfer */
> // curl_easy_setopt(curl, CURLOPT_POSTQUOTE, headerlist);
>
> /* now specify which file to upload */
> curl_easy_setopt(curl, CURLOPT_READDATA, hd_src);
>
> curl_easy_setopt(curl,
> CURLOPT_INFILESIZE_LARGE,(curl_off_t)file_info.st_size);
> printf("%ld\n" ,file_info.st_size);
>
> /* Now run off and do what you've been told! */
> res = curl_easy_perform(curl);
>
> /* clean up the FTP commands list */
> // curl_slist_free_all (headerlist);
>
> /* always cleanup */
> curl_easy_cleanup(curl);
> }
> fclose(hd_src); /* close the local file */
>
> curl_global_cleanup();
> return 0;
> }
>
>
> Also, I noticed on my proftpd server log, that the last command recieved
> from this samples was the pasv. It apear that ssl lost/or didnt connect.
> no firewall running on server
>
> Regards
> Luiz
>
>
Received on 2005-09-14