Usa biblioteca commons.apache.org/proper/commons-net
Controlla qui sotto il codice per scaricare il file dal server FTP:
private Boolean downloadAndSaveFile(String server, int portNumber,
String user, String password, String filename, File localFile)
throws IOException {
FTPClient ftp = null;
try {
ftp = new FTPClient();
ftp.connect(server, portNumber);
Log.d(LOG_TAG, "Connected. Reply: " + ftp.getReplyString());
ftp.login(user, password);
Log.d(LOG_TAG, "Logged in");
ftp.setFileType(FTP.BINARY_FILE_TYPE);
Log.d(LOG_TAG, "Downloading");
ftp.enterLocalPassiveMode();
OutputStream outputStream = null;
boolean success = false;
try {
outputStream = new BufferedOutputStream(new FileOutputStream(
localFile));
success = ftp.retrieveFile(filename, outputStream);
} finally {
if (outputStream != null) {
outputStream.close();
}
}
return success;
} finally {
if (ftp != null) {
ftp.logout();
ftp.disconnect();
}
}
}
fonte
2014-07-07 08:04:41
Ciao, ho installato server di FileZilla FTP in mio desktop. Il suo indirizzo è 127.0.0.1, Port is 14147. Cosa devo dare per UserName, Password, fileName, file locale ?? –
Utilizzare questo link http://lifehacker.com/339887/build-a-home-ftp-server-with-filezilla per creare un utente con filezilla e sapere come usarlo. O controlla questo per le stesse impostazioni http://www.addictivetips.com/windows-tips/how-to-setup-personal-ftp-server-using-filezilla-step-by-step-guide/ –
Che cos'è la libreria? stiamo usando??? Sto ottenendo java.lang.NullPointerException su org.apache.commons.net.ftp.FTP.sendCommand (FTP.java:471) –