S
S
Shady10102014-12-26 22:46:44
Android
Shady1010, 2014-12-26 22:46:44

How to list files via FTP on Android using commons net?

Hello. I sit all day and rack my brains, I don’t know how to display a list of files from my ftp server on android. Since I am a beginner and out of hopelessness I began to rivet anything, I smoked forums and read the docks for a long time and did not understand anything, I really ask for help, explain what I'm doing wrong, I'm doing the examples from the video lessons, but nothing comes out. In Manifests, I also registered the permission.

public class season1 extends ActionBarActivity {
FTPClient client = new FTPClient();
FTPFile files[] = null;
ListView listView;
ArrayAdapteradapter;
ArrayList spisokDocumentov = new ArrayList();
TextView textView ;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.season1);
listView = (ListView) findViewById(R.id.spisok_1);
adapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, spisokDocumentov);
listView.setAdapter(adapter);
Mytask mytask = new Mytask();
mytask.execute();
}
class Mytask extends AsyncTask{
@Override
protected Void doInBackground(Void... voids) { // Void is here because I don't pass anything to it
try { client. connect
("Server address here");
client.login("Login, "Password");
client.changeWorkingDirectory("/www"); //where do I need to display files
client.setFileType(FTP.BINARY_FILE_TYPE); // not clear
here client.enterLocalPassiveMode(); / / Used and enterRemotePassiveMode() - I don't know what they do exactly, don't scold
files = client.listFiles(); // I don't know if it's right to do this
a.add(files);
client.logout();
client.disconnect();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
}}

This is my first project, so I don't understand much yet.
The site deletes some code fragments for some reason (FTPfile[] was deleted in Arraylist and in other places) I
also tried to display listView.setAdapter in
@Override
protected void onPostExecute(Void result) {
super.onPostExecute(result);
}
As a result: either the eternal loading of the progressbar or a blank screen. Maybe it doesn’t connect to the server at all (. Thank you.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question