Debug("Encerrando conexão FTP com o host {$this->GetInfo('host')}"); $close = ftp_close($this->_handler); if ($close) { $this->Debug("Conexão FTP com o host '{$this->GetInfo('host')}' encerrada com sucesso"); $this->Debug(self::$BACKUP_FINALIZADO); } else { $this->Debug("Não foi possível finalizar a conexão FTP com o host '{$this->GetInfo('host')}'"); } } public function Connect(BackupInfo $backup) { $this->backup = $backup; $this->Debug("Abrindo conexã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ão foi possível se conectar ao servidor"); return false; } $this->Debug("Conexã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ão foi possível autenticar o usuá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ão foi possível ativar o modo passivo"); return false; } else { $this->Debug("Modo passivo ativo"); } $this->Debug("Navegando até diretório padrão {$this->GetInfo('dir')}"); if ($this->backup->dir && !$this->Chdir($this->backup->dir)) { $this->Error(sprintf("Não foi possível acessar o diretório padrão: %s\n", $this->backup->dir)); return false; } $this->Debug("Diretório padrã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ão foi possível acesar o diretó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ão foi possível criar o diretó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ão foi possível gravar o arquivo remoto!"); return false; } $this->Debug("Upload concluído com sucesso"); $this->unlink($localFile); return $this->CheckHash($hash, $this->GetInfo('dir') . $remoteFile); } }