0

I am working on a project where I need to access FTP server using its domain, username and password. I want to save data

This is my code, but it does not work. I'm using the Apache Commons FTP Library. Can you help me? Thank you!

 FTPClient client = new FTPClient(); 

            try {
            client.connect("1.2.3.4");
            client.login("USERNAME", "PASSWORD"); 
                String filename = "file1.txt"; 
                FileInputStream fis = null; 
                    fis = new FileInputStream(filename); 
                    client.storeFile(filename, fis); 
                    client.logout(); 
                    fis.close();



        } catch (SocketException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();

            Log.i("tag", "SocketException");
        } catch (IOException e) {
            // TODO Auto-generated catch block

            Log.i("tag", "IOException");
        } 

Error:

could not find class 'org.apache.commons.net.ftp.FTPClient'
Andrew Barber
  • 39,603
  • 20
  • 94
  • 123
lilya
  • 21
  • 1
  • 4

1 Answers1

0

If think that you have that error because you didn't import that library to your project.

Here you have tutorial to that : Adding a library/JAR to an Eclipse Android project

Community
  • 1
  • 1
TN888
  • 7,659
  • 9
  • 48
  • 84
  • Read that : http://commons.apache.org/proper/commons-net/apidocs/org/apache/commons/net/ftp/FTPClient.html – TN888 Aug 02 '13 at 12:16
  • 08-02 12:47:33.727: E/AndroidRuntime(925): FATAL EXCEPTION: Timer-0 08-02 12:47:33.727: E/AndroidRuntime(925): java.lang.NoClassDefFoundError: org.apache.commons.net.ftp.FTPClient 08-02 12:47:33.727: E/AndroidRuntime(925): at com.example.test2.MainActivity.getScreen(MainActivity.java:94) 08-02 12:47:33.727: E/AndroidRuntime(925): at com.example.test2.MainActivity.access$0(MainActivity.java:57) 08-02 12:47:33.727: E/AndroidRuntime(925): at com.example.test2.MainActivity$1.run(MainActivity.java:48) 08-02 12:47:33.727: E/AndroidRuntime(925): at java.util.Timer$TimerImpl.run(Timer.java:284) – lilya Aug 02 '13 at 12:51