1. Download our Official Android App: Forums for Android!

Apps Android FTP API UnkownHostException

Discussion in 'Android Development' started by bruno386, Jun 26, 2010.

  1. bruno386

    bruno386 Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    8
    Joined:
    Jun 26, 2010

    Jun 26, 2010
    8
    0
    5
    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 Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    8
    Joined:
    Jun 26, 2010

    Jun 26, 2010
    8
    0
    5
    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 Lurker
    Rank:
    None
    Points:
    5
    Posts:
    8
    Joined:
    Feb 2, 2011

    Feb 2, 2011
    8
    0
    5
    Add android.permission.INTERNET in AndroidManifest.xml file. This should hel.
     

Share This Page

Loading...