Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parsing ftp url that username/password/path has special characters like @, /

Generally, ftp url format is ftp://user[:pass]@ip[:port]/path

But now I got this string:

ftp://dude:[email protected]/@1.1.1.1/fml

It seems it's ambiguous because the parse result can be:

  1. password=1.1.1.1, [email protected]/fml
  2. [email protected]/, path=fml

Should I have to just tell the client this is illegal, or is there any more friendly way to deal with it? Thanks..

like image 876
wolf5x Avatar asked May 08 '12 04:05

wolf5x


1 Answers

Special Characters in Usernames and Passwords

If your remote server requires authentication, you can include username and password in the input url string. Usernames and passwords should have the following special characters percent-encoded:

] [ ? / < ~ # ` ! @ $ % ^ & * ( ) + = } | : " ; ' , > { space

Examples:

http://example.com/path/to/input.avi
https://example.com/path/to/input.mov
ftp://example.com/path/to/input.mp3
sftp://example.com/path/to/input.3gp
https://s3.amazonaws.com/bucket-name/input.mpeg
s3://bucket-name/input.mpeg (shorthand for the full HTTP S3 url)
Examples (with username "user" and password "pass!word"):

http://user:pass%[email protected]/path/to/input.avi
https://user:pass%[email protected]/path/to/input.mov
ftp://user:pass%[email protected]/path/to/input.mp3
sftp://user:pass%[email protected]/path/to/input.3gp
ftp://user:pass%[email protected]/path/to/input.mp3
Some servers require the username include your domain name (username "[email protected]" and password "pass!word"):

http://user%40example.com:pass%[email protected]/path/to/input.avi
https://user%40example.com:pass%[email protected]/path/to/input.mov
ftp://user%40example.com:pass%[email protected]/path/to/input.mp3
sftp://user%40example.com:pass%[email protected]/path/to/input.3gp
ftp://user%40example.com:pass%[email protected]/path/to/input.mp3
like image 164
hram908 Avatar answered Sep 26 '22 01:09

hram908