Guest User

Untitled

a guest
Nov 8th, 2017
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.99 KB | None | 0 0
  1. /**
  2. * Metodo que realizara la conexion a traves de FTP Buscara la carpeta "www" y
  3. * la descargara en el path de destino indicado.
  4. *
  5. * @param host
  6. * recibe el host a conectarse
  7. * @param usr
  8. * recibe el user a conectarse
  9. * @param pass
  10. * la contraseña del usuario
  11. * @param carpetaRemota
  12. * la carpeta a la que se le va a hacer la copia
  13. * @throws InterruptedException
  14. */
  15.  
  16. public void metodoBackupFtp(String host, String usr, String pass, String carpetaRemota, String destino) {
  17. boolean connected, disconnected;
  18. try {
  19. FTPClient clienteFtp = new FTPClient();
  20. System.err.println("Datos de conexiónnHost:" + host + "nUser:" + usr + "nPass:" + pass);
  21. clienteFtp.connect(host);
  22. connected = clienteFtp.login(usr, pass);
  23. clienteFtp.enterLocalPassiveMode();
  24. clienteFtp.setFileType(FTP.BINARY_FILE_TYPE);
  25. if (connected) {
  26. System.out.println("Conectado al FTP!");
  27. System.err.println("Descarga de carpeta Carpeta Remota: " + carpetaRemota + "Destino: " + pathDestino);
  28. } else {
  29. System.err.println("ERROR:Fallo la conexión al FTP => " + host + "n");
  30.  
  31. }
  32.  
  33. clienteFtp.enterLocalPassiveMode();
  34.  
  35. FTPFile[] files = clienteFtp.listFiles();
  36.  
  37. String[] sfiles = null;
  38. if (files != null) {
  39. sfiles = new String[files.length];
  40. for (int i = 0; i < files.length; i++) {
  41. System.out.println(sfiles[i] = files[i].getName());
  42.  
  43. }
  44.  
  45. }
  46. // Se descarga el archivo
  47. Aquí está lo más importante//FTPDown.retrieveDir(clienteFtp, carpetaRemota, destino);
  48. disconnected = clienteFtp.logout();
  49. if (disconnected) {
  50. System.out.println("Desconectado!");
  51.  
  52.  
  53. }
  54. clienteFtp.disconnect();
  55. } catch (SocketException e) {
  56. System.out.println("ERROR:SocketException");
  57. } catch (IOException e) {
  58. System.out.println("ERROR:IOException");
  59.  
  60. }
  61. }
Add Comment
Please, Sign In to add comment