55

I'm looking for a java library that works on the android that can download and resume files from an FTP server. Does anyone know of such a library. I've found lots of client apps, but no stand alone libraries.

Darthg8r
  • 12,377
  • 15
  • 63
  • 100
  • 1
    Did you read [this resource](http://www.javaworld.com/javaworld/jw-04-2003/jw-0404-ftp.html)? You can pick something from it. Specifically [this page](http://www.javaworld.com/javaworld/jw-04-2003/ftp/jw-0404-ftptable.html). – Bostone Oct 14 '09 at 19:02
  • 1
    So how about writing just an answer with that content? – mliebelt Nov 12 '14 at 21:02

1 Answers1

90

Try using apache commons ftp

FTPClient ftpClient = new FTPClient();
ftpClient.connect(InetAddress.getByName(server));
ftpClient.login(user, password);
ftpClient.changeWorkingDirectory(serverRoad);
ftpClient.setFileType(FTP.BINARY_FILE_TYPE);

BufferedInputStream buffIn = null;
buffIn = new BufferedInputStream(new FileInputStream(file));
ftpClient.enterLocalPassiveMode();
ftpClient.storeFile("test.txt", buffIn);
buffIn.close();
ftpClient.logout();
ftpClient.disconnect();
Andrii Abramov
  • 10,019
  • 9
  • 74
  • 96
jfarrell
  • 4,480
  • 3
  • 21
  • 14
  • 1
    I've started using apache commons ftp and it's a beaut. – MattK Aug 22 '10 at 14:46
  • 10
    very very inportant - active mode doesn't work on your android device. You must enter passive mode. so in between connect and login put this: ftpClient.enterLocalPassiveMode(); – MattK Aug 29 '10 at 20:29
  • are you sure that there are apache comms ftp client api on android ? – Reno Jan 16 '11 at 11:38
  • 6
    @Reno i'm positive you can include the jar in your project and it will run with no issues. Have it working in several apps and it works great. – jfarrell Apr 12 '11 at 21:24
  • 1
    thanks for replying, I've already done this and its excellent. ^^ Oh and if you're not using this already, try out [Proguard](http://proguard.sourceforge.net/index.html#/manual/examples.html) for shrinking the jar further. I highly recommend it. – Reno Apr 13 '11 at 07:36
  • i get `java.net.SocketException: Connection reset` when invoking the `storeFile` command... :( how can i fix this? – Oneiros Nov 30 '11 at 22:56
  • There is also a nice [FTP client example at apache commons](https://commons.apache.org/proper/commons-net/examples/ftp/FTPClientExample.java). – scai Jun 22 '16 at 16:21
  • 14
    For anyone looking at this years later, Apache Commons Net is working for me. Use `implementation 'commons-net:commons-net:3.6'` in build.gradle (Module: app) dependences. – Kartik Chugh Jan 17 '18 at 04:02