You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

132 lines
3.3 KiB

<?php
/**
* ABSTRAÇÃO DOS METODOS DO PHP
*
* Classe para realizar conexao com servidore via FTP
*
* @auth Lucas Awade
* @version 1.0.0
* @date 27/01/2020
*/
class FTPAccess {
/** @conexao */
private $connection;
/** @constantes */
const CONF_FTP_TIMEOUT = 30;
function __construct($server, $port) {
$this->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;
}
}