cURL / Mailing Lists / curl-library / Single Mail

curl-library

libcurl FTP: CURLOPT_USERNAME and CURLOPT_PASSWORD not working in MAC OS X

From: Ravi Kishore Reddy G <ravikishoreg_at_gmail.com>
Date: Wed, 29 Apr 2009 19:46:19 +0530

Hi All,

I tried on libcurl version 7.19.3

The below code is working perfectly fine in Windows. The problem is
only in Mac (I tried on 10.5.6).
When I enabled verbose and checked the console, it is actually trying
to login as
USER anonymous
PASS ftp_at_example.com

int main()
{

string filePath = "/abcd.txt";

curl_global_init(CURL_GLOBAL_ALL);
CURL* handle = curl_easy_init();

curl_easy_setopt(handle, CURLOPT_VERBOSE, 1L);
curl_easy_setopt(handle, CURLOPT_UPLOAD, 1L);
curl_easy_setopt(handle, CURLOPT_FTP_CREATE_MISSING_DIRS, 1L);
curl_easy_setopt(handle, CURLOPT_PORT, 21);

//URL and Login Information
curl_easy_setopt(handle, CUROPT_URL, "ftp://.../abcd.txt");
curl_easy_setopt(handle, CURLOPT_USERNAME, "username");
  //PROBLEM
curl_easy_setopt(handle, CURLOPT_PASSWORD, "password");
 //PROBLEM

//Set File Size
struct stat fileInfo;
stat(filePath.c_str(), &fileInfo);
curl_easy_setopt(handle, CURLOPT_INFILESIZE_LARGE,
(curl_off_t)fileInfo.st_size);

FILE* fp = fopen(filePath.c_str() ,"rb");
curl_easy_setopt(handle, CURLOPT_READDATA, fp);
CURLcode err = curl_easy_perform(handle);
fclose(fp);

curl_easy_cleanup(handle);
curl_global_cleanup();

}

Instead of CURLOPT_USERNAME and CURLOPT_PASSWORD when I changed it to
curl_easy_setopt(handle, CURLOPT_USERPWD, "username:password");
it worked

This also worked
curl_easy_setopt(handle, CUROPT_URL, "ftp://username:password@.../abcd.txt");

But what to do if password or username itself is having a semi colon(:) in it.

Is this a bug in libcurl or am I doing something wrong?

Thanks,
Ravi.
Received on 2009-04-29