Consulta sobre FTP

53 views
Skip to first unread message

Leandro Spadaro

unread,
Nov 2, 2011, 3:59:53 PM11/2/11
to Java android, Grupo Java J2ME JAVA
Buenas,
 
Tengo una duda sobre FTP, resulta que hice dos metodos uno para subir archivo mediante ftp y otro para bajar archivos
desde el servidor por ftp.
 
El metodo para subir archivos funciona bien, pero el metodo para descargar archivo me da error en el path del servidor
lo raro es que funciona bien para subier el archivo. La carpeta en el servidor tiene todos los permisos
 
Linea que da error:
InputStream myFileStream = ftpClient.retrieveFileStream(pathServidor + nombreArchivoServidor);
 
El ejemplo que estoy siguiendo es:
http://stackoverflow.com/questions/3482583/apache-ftpclient-failing-to-download-larger-files
 
Aca el código.
 

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");

}

}
Reply all
Reply to author
Forward
0 new messages