views:

344

answers:

1

It looks like standard Java URL class FTP client cannot work with username having characters such as "@" and ".".

The username I get from my hosting provider is something like "[email protected]", so the whole URL looks like "ftp://[email protected]:[email protected]". It works perfectly with all ftp clients, but apparently not with Java. Any suggestions

+2  A: 

Have you tried to encode these characters, i.e. username%40domain.com:password?

String ftpUser = URLEncoder.encode(username, "UTF-8");
String ftpPass = URLEncoder.encode(password, "UTF-8");
String url = String.format("ftp://%s:%[email protected]", ftpUser, ftpPass);
sfussenegger
Thanks for the tip, it worked after I moved ":" out from the URLEncoder.encode()
Demiurg