|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Autor: Rafael Sales
|
|
|
|
|
* Email: msn:raphasales@hotmail.com
|
|
|
|
|
*
|
|
|
|
|
* Modifica: 17/09/2013
|
|
|
|
|
* Autor: Amarildo Pereira
|
|
|
|
|
* Email: amrlcba@terra.com.br
|
|
|
|
|
*
|
|
|
|
|
* Modifica: 24/08/2017
|
|
|
|
|
* Autor: Victor Mendon<EFBFBD>a
|
|
|
|
|
* Email: androidmend@gmail.com
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
final class BackupInfo {
|
|
|
|
|
|
|
|
|
|
public $proto;
|
|
|
|
|
public $host;
|
|
|
|
|
public $anon; //anonymous
|
|
|
|
|
public $user;
|
|
|
|
|
public $pass;
|
|
|
|
|
public $dir;
|
|
|
|
|
public $dirAtual;
|
|
|
|
|
public $port = 21;
|
|
|
|
|
public $timeout = 90;
|
|
|
|
|
public $messge;
|
|
|
|
|
public $realMessge;
|
|
|
|
|
public $hasError = false;
|
|
|
|
|
public $backupHandler = null;
|
|
|
|
|
|
|
|
|
|
public function __construct($dest, AbstractBackup $backupHandler) {
|
|
|
|
|
$this->proto = $dest['proto'];
|
|
|
|
|
$this->host = str_replace("\\", "/", $dest['host']);
|
|
|
|
|
$this->anon = ($dest['anon'] == 1);
|
|
|
|
|
$this->user = $this->anon ? "anonymous" : str_replace("\\", "/", $dest['user']);
|
|
|
|
|
$this->pass = $this->anon ? "" : $dest['pass'];
|
|
|
|
|
$this->dir = $this->VerBarraPath(str_replace("\\", "/", $dest['dir']));
|
|
|
|
|
if ($dest['port'] && $this->proto != 4) {
|
|
|
|
|
$this->port = $dest['port'];
|
|
|
|
|
}
|
|
|
|
|
if ($dest['timeout']) {
|
|
|
|
|
$this->timeout = $dest['timeout'];
|
|
|
|
|
}
|
|
|
|
|
$this->backupHandler = $backupHandler;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function connect() {
|
|
|
|
|
|
|
|
|
|
if (is_null($this->proto) || empty($this->proto)) {
|
|
|
|
|
$this->Except("Nenhum protocolo informado para a realiza<EFBFBD><EFBFBD>o do backup");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Tenta se conectar ao servidor destino de acordo com o protocolo
|
|
|
|
|
*/
|
|
|
|
|
$this->backupHandler->Connect($this);
|
|
|
|
|
|
|
|
|
|
return !$this->hasError;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function GetMessage() {
|
|
|
|
|
return $this->messge;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function GetRealMessage() {
|
|
|
|
|
return $this->realMessge;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function Except($msg, $realMessage = '') {
|
|
|
|
|
$this->hasError = true;
|
|
|
|
|
$this->messge = $msg;
|
|
|
|
|
$error = error_get_last();
|
|
|
|
|
$this->realMessge = $realMessage . "[" . $error['message'] . "]\n";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function VerBarraPath($path) {
|
|
|
|
|
if (substr($path, -1) != '/') {
|
|
|
|
|
return $path . '/';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $path;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function GetMode($file) {
|
|
|
|
|
return (StringClass::ContemTexto($file, '.txt')) || (StringClass::ContemTexto($file, '.sql')) ? FTP_ASCII : FTP_BINARY;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getBackupHandler() {
|
|
|
|
|
return $this->backupHandler;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Retorna o <EFBFBD>ltimo erro lan<EFBFBD>ado pelo $backupHandler
|
|
|
|
|
* @return null|string
|
|
|
|
|
*/
|
|
|
|
|
public function GetLastHandlerException() {
|
|
|
|
|
return $this->backupHandler->getExceptionMessage();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|