Answer the question
In order to leave comments, you need to log in
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;
}
}}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question