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