how to resolve host exception?

84 Views Asked by At

please take me out this problem ,I am trying to get file from Ftp server . here is my code which i am continuously getting exception like java.net.unknownHostException :ftpbrasnet.no-ip.org. i have tried in browser its working.

FTPClient client = new FTPClient();
FileOutputStream Foutput = null;
try {
    client.connect("ftp://ftpbrasnet.no-ip.org/"); // My Exceptionis here
    client.login("win7", "123");
    // Create an OutputStream for the file
    String filename = "files.txt";
    Foutput = new FileOutputStream(filename);
    // Fetch file from server
    client.retrieveFile("/" + filename, Foutput);
} 
catch (IOException e) 
{
    Log.e("ERROR", e.getStackTrace().toString());
}
finally 
{
    try 
    {
        if (Foutput != null) {
            Foutput.close();
        }
        client.disconnect();
    } catch (IOException e) {
        Log.e("ERROR", e.getStackTrace().toString());
    }
}

}

and here is my manifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="Net.estoque"
      android:versionCode="1"
      android:versionName="1.0">
     <uses-sdk
        android:minSdkVersion="9"
        android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <application android:label="@string/app_name" >
        <activity android:name="Netestoque"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
</manifest> 
1

There are 1 best solutions below

0
On

Have you tried removing the protocol from the URL, like so:

client.connect("ftpbrasnet.no-ip.org/");