Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Metodo que realizara la conexion a traves de FTP Buscara la carpeta "www" y
- * la descargara en el path de destino indicado.
- *
- * @param host
- * recibe el host a conectarse
- * @param usr
- * recibe el user a conectarse
- * @param pass
- * la contraseña del usuario
- * @param carpetaRemota
- * la carpeta a la que se le va a hacer la copia
- * @throws InterruptedException
- */
- public void metodoBackupFtp(String host, String usr, String pass, String carpetaRemota, String destino) {
- boolean connected, disconnected;
- try {
- FTPClient clienteFtp = new FTPClient();
- System.err.println("Datos de conexiónnHost:" + host + "nUser:" + usr + "nPass:" + pass);
- clienteFtp.connect(host);
- connected = clienteFtp.login(usr, pass);
- clienteFtp.enterLocalPassiveMode();
- clienteFtp.setFileType(FTP.BINARY_FILE_TYPE);
- if (connected) {
- System.out.println("Conectado al FTP!");
- System.err.println("Descarga de carpeta Carpeta Remota: " + carpetaRemota + "Destino: " + pathDestino);
- } else {
- System.err.println("ERROR:Fallo la conexión al FTP => " + host + "n");
- }
- clienteFtp.enterLocalPassiveMode();
- FTPFile[] files = clienteFtp.listFiles();
- String[] sfiles = null;
- if (files != null) {
- sfiles = new String[files.length];
- for (int i = 0; i < files.length; i++) {
- System.out.println(sfiles[i] = files[i].getName());
- }
- }
- // Se descarga el archivo
- Aquí está lo más importante//FTPDown.retrieveDir(clienteFtp, carpetaRemota, destino);
- disconnected = clienteFtp.logout();
- if (disconnected) {
- System.out.println("Desconectado!");
- }
- clienteFtp.disconnect();
- } catch (SocketException e) {
- System.out.println("ERROR:SocketException");
- } catch (IOException e) {
- System.out.println("ERROR:IOException");
- }
- }
Add Comment
Please, Sign In to add comment