This video shows quick steps to create your FTP client Android App. It demonstrates the example by connecting to a FTP server created on the local LAN network.
I hope you like this video. For any questions, suggestions or appreciation please contact us at: https://programmerworld.co/contact/ or email at: programmerworld1990@gmail.com
Complete source code and other details:
GitHub: https://github.com/programmerworld1990/ftpserverconnect.git
Maven Dependency: https://mvnrepository.com/artifact/commons-net/commons-net/3.10.0
package com.programmerworld.ftpserverconnect;
import android.os.Bundle;
import android.os.StrictMode;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
import org.apache.commons.net.ftp.FTPClient;
import java.io.IOException;
public class MainActivity extends AppCompatActivity {
private TextView textView;
private EditText editTextFTPServer, editTextUserName, editTextPassword;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
setContentView(R.layout.activity_main);
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
textView = findViewById(R.id.textViewStatus);
editTextFTPServer = findViewById(R.id.editTextFTPServer);
editTextUserName = findViewById(R.id.editTextUserName);
editTextPassword = findViewById(R.id.editTextPassword);
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
return insets;
});
}
public void buttonConnectToFTP(View view){
FTPClient ftpClient = new FTPClient();
try {
ftpClient.connect(editTextFTPServer.getText().toString());
ftpClient.login(editTextUserName.getText().toString(), editTextPassword.getText().toString());
ftpClient.changeWorkingDirectory("/usb1_1/Files/");
textView.setText(ftpClient.printWorkingDirectory());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.FTPServerConnect"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
plugins {
alias(libs.plugins.androidApplication)
}
android {
namespace = "com.programmerworld.ftpserverconnect"
compileSdk = 34
defaultConfig {
applicationId = "com.programmerworld.ftpserverconnect"
minSdk = 33
targetSdk = 34
versionCode = 1
versionName = "1.0"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
isMinifyEnabled = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
}
dependencies {
implementation(libs.appcompat)
implementation(libs.material)
implementation(libs.activity)
implementation(libs.constraintlayout)
testImplementation(libs.junit)
androidTestImplementation(libs.ext.junit)
androidTestImplementation(libs.espresso.core)
// https://mvnrepository.com/artifact/commons-net/commons-net
implementation(libs.commons.net)
}
[versions]
agp = "8.3.0"
commonsNet = "3.10.0"
junit = "4.13.2"
junitVersion = "1.1.5"
espressoCore = "3.5.1"
appcompat = "1.6.1"
material = "1.11.0"
activity = "1.8.0"
constraintlayout = "2.1.4"
[libraries]
commons-net = { module = "commons-net:commons-net", version.ref = "commonsNet" }
junit = { group = "junit", name = "junit", version.ref = "junit" }
ext-junit = { group = "androidx.test.ext", name = "junit", version.ref = "junitVersion" }
espresso-core = { group = "androidx.test.espresso", name = "espresso-core", version.ref = "espressoCore" }
appcompat = { group = "androidx.appcompat", name = "appcompat", version.ref = "appcompat" }
material = { group = "com.google.android.material", name = "material", version.ref = "material" }
activity = { group = "androidx.activity", name = "activity", version.ref = "activity" }
constraintlayout = { group = "androidx.constraintlayout", name = "constraintlayout", version.ref = "constraintlayout" }
[plugins]
androidApplication = { id = "com.android.application", version.ref = "agp" }
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:id="@+id/textViewStatus"
android:layout_width="268dp"
android:layout_height="85dp"
android:text="Hello World!"
android:textAlignment="center"
android:textSize="24sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.594" />
<EditText
android:id="@+id/editTextFTPServer"
android:layout_width="258dp"
android:layout_height="68dp"
android:layout_marginStart="76dp"
android:layout_marginTop="16dp"
android:ems="10"
android:hint="FTP Server Name/ IP"
android:inputType="text"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<EditText
android:id="@+id/editTextUserName"
android:layout_width="248dp"
android:layout_height="57dp"
android:layout_marginStart="87dp"
android:layout_marginTop="33dp"
android:ems="10"
android:hint="Enter Login UserName"
android:inputType="text"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/editTextFTPServer" />
<EditText
android:id="@+id/editTextPassword"
android:layout_width="254dp"
android:layout_height="77dp"
android:layout_marginStart="76dp"
android:layout_marginTop="12dp"
android:ems="10"
android:hint="Enter Password"
android:inputType="textPassword"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/editTextUserName" />
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="120dp"
android:layout_marginTop="24dp"
android:onClick="buttonConnectToFTP"
android:text="Connect to FTP"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/editTextPassword" />
</androidx.constraintlayout.widget.ConstraintLayout>
Screenshots: