wolf5x
wolf5x

Reputation: 106

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..

Upvotes: 5

Views: 7870

Answers (1)

hram908
hram908

Reputation: 394

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

Upvotes: 6

Related Questions