connect($server, $port); } /** * Informa o servidor FTP para inciar uma conexao. * @param string $server * @param string|int $port * @return boolean */ function connect($server, $port = 21) { $this->connection = ftp_connect($server, $port, self::CONF_FTP_TIMEOUT); if ($this->connection) { return true; } else { return false; } } /** * Autentica as credencias para conectar ao FTP. * @param string $username * @param string $password * @return boolean */ function authentication($username, $password) { if (ftp_login($this->connection, $username, $password)) { return true; } else { return false; } } /** * Modo de conexao Passivo. * @param boolean $mode * @return boolean */ function mode_passive($mode) { if (!is_bool($mode)) { return false; } if (ftp_pasv($this->connection, $mode)) { return true; } else { return false; } } /** * Troca de pasta no FTP. * @param string $directory * @return boolean */ function ch_dir($directory) { if (ftp_chdir($this->connection, $directory)) { return true; } else { return false; } } /** * Lista os diretorios de um pasta ou caminho. */ function list_dir($directory) { return ftp_nlist($this->connection, $directory); } /** * Cria uma pasta no FTP. * @param string $directory * @return boolean */ function mk_dir($directory) { if (ftp_mkdir($this->connection, $directory)) { return true; } else { return false; } } /** * Envia o arquivo para o FTP. * @param string $remote_file * @param string $local_file * @return boolean */ function send_file($remote_file, $local_file) { if (ftp_put($this->connection, $remote_file, $local_file, FTP_BINARY)) { return true; } else { return false; } } /** * Fecha conexao com o FTP. * @return boolean */ function connection_close() { if (ftp_close($this->connection)) { return true; } else { return false; } } function getConnection() { return $this->connection; } }