cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: Reg:FTP upload in libcurl

From: Dan Fandrich <dan_at_coneharvesters.com>
Date: Thu, 19 Jun 2008 21:24:08 -0700

On Fri, Jun 20, 2008 at 09:12:56AM +0530, nagarajan.sreenivasan_at_wipro.com wrote:
> Connect()
> {
> char * REMOTE_URL=new char[100];
> strcpy(REMOTE_URL,"ftp://");
>
> strncat(REMOTE_URL,userName,strlen(userName));
> strcat(REMOTE_URL,":");
> strncat(REMOTE_URL,passWord,strlen(passWord));
> strcat(REMOTE_URL,"@");
> strncat(REMOTE_URL,hostName,strlen(hostName));

You're not providing a file name here in the URL. The remote server has no
way to know what to call the file without it, so this will cause an error.

Also, what's the point of using strncat here? By providing a length equal
to the string to concatenate, the function becomes identical to strcat.
You really want to use strlcat here instead if you're worried about
buffer overflows.

>
> CurlInternalSettings();
> curl_easy_setopt(curl,CURLOPT_URL,REMOTE_URL);
> res = curl_easy_perform(curl);
> }
>
> void CurlInternalSettings()
> {
> curl_global_init(CURL_GLOBAL_ALL);
>
> curl = curl_easy_init();
> if(curl) {
> curl_easy_setopt(curl,CURLOPT_VERBOSE,1);
>
> }
>
> UploadFile_FTP(remoetpath,local path)
> {
>
> FILE *hd_src;
> struct stat file_info;
>
> char *UPLOAD_FILE_AS=new char[255];
>
> strncpy(UPLOAD_FILE_AS,remotePathName,strlen(remotePathName));

This string isn't actually used anywhere.

>
> struct curl_slist *headerlist=NULL;
>
> char *buf_1=new char [255];
>
> if(curl) {
> headerlist = curl_slist_append(headerlist, buf_1);
> // headerlist = curl_slist_append(headerlist, buf_2);
> curl_easy_setopt(curl,CURLOPT_VERBOSE,1);
> // curl_easy_setopt(curl, CURLOPT_READFUNCTION, read_callback);
> // curl_easy_setopt(curl, CURLOPT_INFILE,&file_info);
> curl_easy_setopt(curl, CURLOPT_UPLOAD,1);
> curl_easy_setopt(curl, CURLOPT_INFILESIZE,
> (curl_off_t)file_info.st_size);
> curl_easy_setopt(curl,CURLOPT_URL,);------------------------------->what
> should this line be () or is there any other way i can send my file

As mentioned above, this URL needs to include the file name of the remote
file.

> curl_easy_setopt(curl, CURLOPT_PREQUOTE, headerlist);
> curl_easy_setopt(curl, CURLOPT_READDATA, hd_src);

hd_src isn't opened anywhere. You need to call fopen() on it to provide some
data to send. I've forgotten what platform you're using, but this won't
always work for Windows.

> res = curl_easy_perform(curl);
> }

>>> Dan

-- 
http://www.MoveAnnouncer.com              The web change of address service
          Let webmasters know that your web site has moved
Received on 2008-06-20