FTP client for Android
FTP4jAnd is an FTP client library for Android, based on the ftp4j Java library. Control of ftp4j is implemented as an application service, with a helper class provided for service access. Two separate interfaces are also provided for service and download status callbacks.
FTP4jAnd is used in AndPlug music player application for Android devices.
- Android 4.0.3 (API Level: 15) or later (
ICE_CREAM_SANDWICH_MR1) - Android Gradle Plugin 8.11.1 or later (
gradle:8.11.1) - ftp4j Version 1.7.2
- Check out a local copy of FTP4jAnd repository
- Download ftp4j and extract JAR package
- Build library with Gradle, using Android Studio or directly from the command line
Setup steps:
$ git clone https://github.com/omicronapps/FTP4jAnd.git
$ cd FTP4jAnd/ftplib/libs/
$ unzip -j ftp4j-1.7.2.zip ftp4j-1.7.2/ftp4j-1.7.2.jar
FTP4jAnd includes both instrumented unit tests and a simple test application.
Located under ftplib/src/androidTest.
These tests are run on a hardware device or emulator, and verifies correct operation of the FTPService and FTPController implementations and their usage of the ftp4j library.
Located under app/src/main.
FTP4jAnd is controlled through the following class and interfaces:
FTPController- service management classFTPController.IFTPCallback- service callback interfaceFTPController.IFTPDownload- download status callback interface
Implement FTPController.IFTPCallback callback interface to receive command completion callbacks:
import com.omicronapplications.ftplib.FTPController;
class FTPCallback implements FTPController.IFTPCallback {
...
}
Implement FTPController.IFTPDownload callback interface to receive download status updates:
import com.omicronapplications.ftplib.FTPController;
class FTPDownload implements FTPController.IFTPDownload {
...
}
Create callback instances and controller, and start FTP client service:
FTPCallback callback = new FTPCallback();
FTPDownload download = new FTPDownload();
FTPController controller = new FTPController(getApplicationContext());
controller.setCallbacks(callback, download);
controller.start();
Once service is running, connect to FTP server:
class FTPCallback implements FTPController.IFTPCallback {
@Override
public void start() {
controller.connect("ftp.server.name", 21);
}
}
Log in user after a connection has been established:
class FTPCallback implements FTPController.IFTPCallback {
@Override
public void connect(int exception, String[] message) {
controller.login("anonymous", "");
}
}
After the used has been logged in, change the remote directory:
class FTPCallback implements FTPController.IFTPCallback {
@Override
public void login(int exception) {
controller.changeDirectory("...");
}
}
On entering new remote directory, request list of files:
class FTPCallback implements FTPController.IFTPCallback {
@Override
public void changeDirectory(int exception) {
controller.list();
}
}
List files in current directory:
class FTPCallback implements FTPController.IFTPCallback {
@Override
public void list(int exception, FTPFile[] files) {
for (FTPFile file : files) {
// List files
}
}
}
Download file from FTP server to local storage:
String remoteFileName = "...";
String localFileName = "...";
controller.download(remoteFileName, localFileName);
Wait for download to complete:
class FTPDownload implements FTPController.IFTPDownload {
@Override
public void completed() {
}
}
Disconnect from FTP server:
controller.disconnect();
After disconnecting from FTP server, stop FTP client service:
class FTPCallback implements FTPController.IFTPCallback {
@Override
public void disconnect(int exception) {
controller.stop();
}
}
Copyright (C) 2019-2025 Fredrik Claesson
- 1.0.0 Initial release
- 1.1.0 Migrated to AndroidX
- 1.2.0 FTP service refactored, support for multiple download requests
- 1.3.0 Minor bugfix
- 1.4.0 Change to Apache License Version 2.0
- 1.5.0 Target Android 15 (API level 35)
FTP4jAnd is licensed under Apache License Version 2.0.