I am trying to parse a FTP URL that has some special characters like @ in the username and password:
username:p@sswrd@ftp.myhost.com/mypath
When I try:
URI.parse(url)
I get:
URI::InvalidURIError: the scheme ftp does not accept registry part: username:p@sswrd@ftp.myhost.com (or bad hostname?)
Then, I tried to encode the url:
url = URI.encode(url, '@')
But also got another error:
URI::InvalidURIError: the scheme ftp does not accept registry part: username:p%40sswrd%40ftp.myhost.com (or bad hostname?)
Finally, I tried another solution:
URI::FTP.build(:userinfo => 'username:p@sswrd', :host=>'ftp.myhost.com', :path => '/mypath')
But I also got an error:
URI::InvalidComponentError: bad component(expected user component): p@ssword
I am using ruby 1.8.7.
1 Answer