cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: libcurl question - passwords with '%'...

From: Daniel Stenberg <daniel_at_haxx.se>
Date: Mon, 5 May 2003 16:24:20 +0200 (CEST)

On Mon, 5 May 2003, Philip Butler wrote:

> I am using libcurl to do some FTP'ing... The one problem that I am
> running into is that I need to enter a password with a '%' - for
> example, a site URL may be
> ftp://username:pass%word@ftp.something.com/path/path/file.ext. My app
> works if the password does not have an embedded '%'.
>
> I have seen the docs on curl_escape and curl_unescape - not sure if
> these would help me or not.

You need to URL-encode the password (and the user name too in case you want
to support non-URL-supported letters in the user name). When that is made, a
'%' letter appears as '%25'.

You can use curl_escape() to produce an URL-formatted string out of a
"normal" string. Something like this:

 char *encoded_password = curl_escape(password, 0);
 char *encoded_username = curl_escape(username, 0);

 sprintf(url, "ftp://%s@%s:ftp.something.com/path/path/file.ext",
         encoded_username, encoded_password);

 curl_free(encoded_password);
 curl_free(encoded_username);

-- 
 Daniel Stenberg -- curl, cURL, Curl, CURL. Groks URLs.
-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
Received on 2003-05-05