String ipServer =
"111.11.11.11";String usuario =
"usuario";String clave =
"clave";String pathServer =
"/upload/"; String nombreArchivoServidor = "salida.txt";String nombreArchivoSdCard = "entradaPrueba.txt";
public
static void bajarArchivoFTP (String ipServer, String usuario, String clave, String nombreArchivoSdCard, String pathServidor, String nombreArchivoServidor) throws ConectividadException{
FTPClient ftpClient =
new FTPClient();DataInputStream inputStream =
null;BufferedReader bufferedReader =
null;
try{
ftpClient = conectarFTP(ipServer, usuario, clave);
ftpClient.setFileType(org.apache.commons.net.ftp.FTP.BINARY_FILE_TYPE);
//ftpClient.changeWorkingDirectory(pathServidor);
InputStream myFileStream = ftpClient.retrieveFileStream(pathServidor + nombreArchivoServidor);
inputStream = new DataInputStream(myFileStream);
bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
File fileToWrite = new File("/sdcard/"+ nombreArchivoSdCard);
java.io.FileOutputStream fos = new java.io.FileOutputStream(fileToWrite);
java.io.BufferedOutputStream bout = new BufferedOutputStream(fos,1024);
byte data[] = new byte[1024];
int x = 0;
while((x=myFileStream.read(data,0,1024))>=0){
bout.write(data,0,x);
}
bout.close();
myFileStream.close();
}catch (Exception ex) {
throw new ConectividadException ("Error de sistema");
}
}