Android FTP API UnkownHostException


Last Updated:

  1. bruno386

    bruno386 Member This Topic's Starter

    Joined:
    Jun 26, 2010
    Messages:
    8
    Likes Received:
    0
    Hi,

    I'm experimenting with eclipse and adroid sdk target 1.6.


    I am using it.sauronsoftware.ftp4j.FTPClient;





    Code (Text):
    1.  
    2. package bruno.test;
    3.  
    4. import android.app.Activity;
    5. import android.app.AlertDialog;
    6. import android.os.Bundle;
    7. import java.io.FileInputStream;
    8. import java.io.FileOutputStream;
    9. import java.io.IOException;
    10. import java.io.InputStream;
    11. import java.io.OutputStream;
    12. import java.io.PrintWriter;
    13. import it.sauronsoftware.ftp4j.FTPClient; //this is the ftp class
    14.  
    15.  
    16.  
    17.  
    18.  
    19. public class brunoactivity extends Activity {
    20.    
    21.     @Override
    22.     public void onCreate(Bundle savedInstanceState) {
    23.         super.onCreate(savedInstanceState);
    24.         setContentView(R.layout.main);
    25.        
    26.         try{
    27.         FTPClient client = new FTPClient();
    28.         client.connect("thestorythusfar.co.uk");
    29.         client.login("....", ".....");
    30.         client.upload(new java.io.File("C://test"));
    31.         //client.disconnect(true);
    32.  
    33.  
    34.         }
    35.  
    36.  
    37.         catch (Exception e){
    38.             e.printStackTrace();
    39.             new AlertDialog.Builder(this)
    40.             .setMessage(e.toString())
    41.             .show();
    42.  
    43.  
    44.     }
    45.        
    46.        
    47.     }
    48.    
    49.    
    50. }
    51.  
    52.  
    The app fires up in the emulator and then loads however I always get unkown host exception (this is handled with the catch block) whenever it try to make the connection.


    The emulator seems to be working fine,the browser app laods any web page so its not a problem with the connection to the net.

    The ftp server is fine I use it from any ftp client all the time including console ftp's, no problem there.


    Anyone got any ideas?


    Thanks in advance.
     

    Advertisement
  2. bruno386

    bruno386 Member This Topic's Starter

    Joined:
    Jun 26, 2010
    Messages:
    8
    Likes Received:
    0
    I also tried the same code with the apache commons net ftp class, this gave the error

    Code (Text):
    1.  
    2. java.netSocketException : Permission Denied
    3.  
    4.  
     
  3. arjun.laxman

    arjun.laxman Member

    Joined:
    Feb 2, 2011
    Messages:
    8
    Likes Received:
    0
    Add android.permission.INTERNET in AndroidManifest.xml file. This should hel.
     

Share This Page

Loading...