I am trying to parse a FTP URL that has some special characters like @
in the username and password:
username:p@[email protected]/mypath
When I try:
URI.parse(url)
I get:
URI::InvalidURIError: the scheme ftp does not accept registry part: username:p@[email protected] (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.
require 'net/ftp'
ftp=Net::FTP.new
ftp.connect("ftp.myhost.com",21)
ftp.login("username","p@sswd")
ftp.getbinaryfile("/mypath"){|data| puts data}
ftp.close
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With