|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* To change this license header, choose License Headers in Project Properties.
|
|
|
|
|
* To change this template file, choose Tools | Templates
|
|
|
|
|
* and open the template in the editor.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Description of BackupFTP
|
|
|
|
|
*
|
|
|
|
|
* @author Victor
|
|
|
|
|
*/
|
|
|
|
|
final class BackupFTP extends AbstractBackup {
|
|
|
|
|
|
|
|
|
|
public function __destruct() {
|
|
|
|
|
$this->Debug("Encerrando conex<EFBFBD>o FTP com o host {$this->GetInfo('host')}");
|
|
|
|
|
$close = ftp_close($this->_handler);
|
|
|
|
|
if ($close) {
|
|
|
|
|
$this->Debug("Conex<EFBFBD>o FTP com o host '{$this->GetInfo('host')}' encerrada com sucesso");
|
|
|
|
|
$this->Debug(self::$BACKUP_FINALIZADO);
|
|
|
|
|
} else {
|
|
|
|
|
$this->Debug("N<EFBFBD>o foi poss<EFBFBD>vel finalizar a conex<EFBFBD>o FTP com o host '{$this->GetInfo('host')}'");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function Connect(BackupInfo $backup) {
|
|
|
|
|
$this->backup = $backup;
|
|
|
|
|
$this->Debug("Abrindo conex<EFBFBD>o com o host {$this->GetInfo('host')}");
|
|
|
|
|
$this->_handler = ftp_connect($this->backup->host, $this->backup->port, $this->backup->timeout);
|
|
|
|
|
if (!$this->_handler) {
|
|
|
|
|
$this->Error("N<EFBFBD>o foi poss<EFBFBD>vel se conectar ao servidor");
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
$this->Debug("Conex<EFBFBD>o estabelecida com o host {$this->GetInfo('host')}");
|
|
|
|
|
|
|
|
|
|
$this->Debug("Tentando login com o host {$this->GetInfo('host')}");
|
|
|
|
|
if (!ftp_login($this->_handler, $this->backup->user, $this->backup->pass)) {
|
|
|
|
|
$this->Error("N<EFBFBD>o foi poss<EFBFBD>vel autenticar o usu<EFBFBD>rio no servidor");
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
$this->Debug("Login efetuado com o host {$this->GetInfo('host')}");
|
|
|
|
|
|
|
|
|
|
$passiveMode = ftp_pasv($this->_handler, true);
|
|
|
|
|
if (!$passiveMode) {
|
|
|
|
|
$this->Error("N<EFBFBD>o foi poss<EFBFBD>vel ativar o modo passivo");
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
} else {
|
|
|
|
|
$this->Debug("Modo passivo ativo");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->Debug("Navegando at<EFBFBD> diret<EFBFBD>rio padr<EFBFBD>o {$this->GetInfo('dir')}");
|
|
|
|
|
if ($this->backup->dir && !$this->Chdir($this->backup->dir)) {
|
|
|
|
|
$this->Error(sprintf("N<EFBFBD>o foi poss<EFBFBD>vel acessar o diret<EFBFBD>rio padr<EFBFBD>o: %s\n", $this->backup->dir));
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
$this->Debug("Diret<EFBFBD>rio padr<EFBFBD>o {$this->GetInfo('dir')} encontrado");
|
|
|
|
|
$this->backup->dirAtual = $this->backup->VerBarraPath($this->backup->dir);
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function Chdir($dir) {
|
|
|
|
|
if (!ftp_chdir($this->_handler, $dir)) {
|
|
|
|
|
$this->Error("N<EFBFBD>o foi poss<EFBFBD>vel acesar o diret<EFBFBD>rio destino!\n");
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
$this->backup->dirAtual = $this->backup->VerBarraPath($dir);
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function Mkdir($dir) {
|
|
|
|
|
if (!ftp_mkdir($this->_handler, $dir)) {
|
|
|
|
|
$this->Error("N<EFBFBD>o foi poss<EFBFBD>vel criar o diret<EFBFBD>rio destino![FTP]");
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function Upload(array $dadosArquivo, $remoteFile) {
|
|
|
|
|
$localFile = $dadosArquivo['file'];
|
|
|
|
|
$hash = $dadosArquivo['hash'];
|
|
|
|
|
$debugMsg = sprintf("Iniciando upload do arquivo '%s' para '%s%s%s'...", $localFile, $this->GetInfo('host'), $this->GetInfo('dir'), $remoteFile);
|
|
|
|
|
$this->Debug($debugMsg);
|
|
|
|
|
if (!ftp_put($this->_handler, $remoteFile, $localFile, $this->backup->GetMode($localFile))) {
|
|
|
|
|
$this->Error("N<EFBFBD>o foi poss<EFBFBD>vel gravar o arquivo remoto!");
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
$this->Debug("Upload conclu<EFBFBD>do com sucesso");
|
|
|
|
|
|
|
|
|
|
$this->unlink($localFile);
|
|
|
|
|
|
|
|
|
|
return $this->CheckHash($hash, $this->GetInfo('dir') . $remoteFile);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|