I want upload a text file, I am using org.apache.commons.net.ftp.FTPclient
. The code fails every time.
FTPClient client = new FTPClient();
FileInputStream fis = null;
try {
client.connect("192.168.43.164",21);
client.login("android", "android");
client.setFileType(FTP.BINARY_FILE_TYPE);
client.setFileTransferMode(FTP.BINARY_FILE_TYPE);
String filename = "/sdcard/m.txt";
fis = new FileInputStream(filename);
client.setFileType(FTP.BINARY_FILE_TYPE);
client.storeFile("/web/m.txt", fis);
fis.close();
client.logout();
} catch (IOException e) {
e.printStackTrace();
}
I am following this tutorial : FTP File Upload From Sdcard to server
Logcat Output,
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.vaibhav.myapplication/com.example.vaibhav.myapplication.MainActivity}: android.os.NetworkOnMainThreadException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
FTPClient Upload file.. working for me