URLConnection中未保留的字符到FTP服务器

时间:2017-05-18 12:28:04

标签: android url ftp urlconnection

我有一个Android应用程序,它使用URLConnection从FTP服务器下载文件。 我的代码如下所示:

try {
    String urlString = "ftp" + "://" + URLEncoder.encode(username,"UTF-8") + ":" + URLEncoder.encode(password,"UTF-8") + "@" + address + ":" + port + filepath + file;

    Log.d(TAG, "downloadAndBroadcastSpeed: "+urlString);
    URL url = new URL(urlString);
    URLConnection urlConnection = url.openConnection();
    inputStream = new BufferedInputStream(urlConnection.getInputStream());

    long timeDifference;
    byte data[] = new byte[4094];
    int count;

    while (inputStream.read(data) != -1) {
        //handle inpust stream...
    }
    clearInputStream();
} catch (Exception e) {
    e.printStackTrace();
} finally {
    clearInputStream();
    Log.d(TAG, "downloadAndBroadcast: finally");
}

我尝试使用带有" UTF的URLEncoder.encode()来编码用户名和密码(具有特殊字符,例如!"#€%& /()=?_ * ^) -8&#34 ;.但它似乎不起作用。我在getInputStream()处有例外:

java.io.IOException: Unable to connect to server: Unable to log in to server (PASS): 94.237.32.84

有人有任何想法吗?

0 个答案:

没有答案