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.
Asked
Active
Viewed 8.3k times
55
-
1Did 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
-
1So how about writing just an answer with that content? – mliebelt Nov 12 '14 at 21:02
1 Answers
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
-
10very 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
-
-
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
-
1thanks 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
-
14For 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