FTP URL用户名和带有特殊字符的paassword

Dem*_*urg 4 java ftp special-characters username

看起来标准的Java URL类FTP客户端无法使用具有"@"和"."等字符的用户名.

我从托管服务提供商处获得的用户名是"username@domain.com",因此整个网址看起来像" ftp://username@domain.com:password@domain.com ".它与所有ftp客户端完美配合,但显然不适用于Java.有什么建议

sfu*_*ger 6

你试过编码这些字符,即username%40domain.com:password

String ftpUser = URLEncoder.encode(username, "UTF-8");
String ftpPass = URLEncoder.encode(password, "UTF-8");
String url = String.format("ftp://%s:%s@domain.com", ftpUser, ftpPass);
Run Code Online (Sandbox Code Playgroud)