连接到服务器的密码包含“@”使用ftp协议的符号 [英] Connecting to the server which password contains "@" symbols using ftp protocol

查看:695
本文介绍了连接到服务器的密码包含“@”使用ftp协议的符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在java中使用FTP协议从服务器下载文件。
通过使用以下URL,我可以连接到服务器&下载文件。

I am trying to download files from a server using FTP protocol in java. By using following URL I am able to connect to the server & download files.

URL url = new URL("ftp://"+user+":"+password+"@"+host+"/"+remoteFile+";type=i"); 

但是当我的密码包含@(例如:soft @ 2011)符号时,会引发以下例外:

But when my password contains the "@" (ex : soft@2011) symbol it throws the following exception:

  java.net.UnknownHostException: 2010@192.168.1.100 

无法区分两个@符号。

如何避免此问题?我可以使用任何转义字符来避免这个问题吗?

How can I avoid this problem? Can I use any escape characters to avoid this problem?

推荐答案

URI编码密码(和

URL url = new URL("ftp://" + 
                  URLEncoder.encode(user, "UTF-8") + ":" + 
                  URLEncoder.encode(password, "UTF-8") + "@" + 
                  host + "/" + remoteFile + ";type=i");

这篇关于连接到服务器的密码包含“@”使用ftp协议的符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆