Java Ftpclient Application Doesn't Connect
Solution 1:
I've tried your code and it works ok. Based on the response code you're getting I assume the connection to the server has not been even established. Make sure you have granted your app with INTERNET permission in the manifest file:
<uses-permissionandroid:name="android.permission.INTERNET" />
EDIT: From the exception stack trace it's clear, that you're trying to execute this code from a main thread. In Android 3.0 (Honeycomb) or later you're not permitted to execute any network call in UI thread by default. The reason is simple: network call may block for an indefinite amount of time, effectively freezing application UI. You have two options how to fix it:
Lazy way - Disable therad check for network calls:
StrictMode.ThreadPolicypolicy=newStrictMode.ThreadPolicy.Builder()
.permitAll()
.build();
StrictMode.setThreadPolicy(policy);
You can always enable thread checks again using
StrictMode.ThreadPolicypolicy=newStrictMode.ThreadPolicy.Builder()
.detectAll()
.penaltyLog()
.penaltyDeath()
.build();
StrictMode.setThreadPolicy(policy);
Proper way - execute FTP calls from a background worker thread using AsyncTask. Take a look here for examples and comprehensive explanation about AsyncTasks.
Post a Comment for "Java Ftpclient Application Doesn't Connect"