✏️ 正在编辑: Ftp.php
路径:
/srv/systems_dir/biblioteca_yuppie/library/Yuppie/Ftp.php
提示:
您可以编辑任何文件(包括二进制文件),但请注意不当修改可能导致文件损坏。
<?php class Yuppie_Ftp { private $_connection; private $_host; private $_userName; private $_password; private $_typeConnection; private $_port; private $_isConnected = false; /** * Abre uma conexao FTP para o host especificado * @param string $_host * @param string $_userName * @param string $_password * @param int $_typeConnection (true = PASSIVA, false = ATIVA) */ function __construct($_host, $_userName, $_password, $_typeConnection = false, $_port = 21) { $this->_host = $_host; $this->_userName = $_userName; $this->_password = $_password; $this->_typeConnection = $_typeConnection; $this->_port = $_port; //abre a conexão $this->connect(); } public function getConnection() { return $this->_connection; } public function setConnection($connection) { $this->_connection = $connection; } public function getHost() { return $this->_host; } public function setHost($host) { $this->_host = $host; } public function getUserName() { return $this->_userName; } public function setUserName($userName) { $this->_userName = $userName; } public function getPassword() { return $this->_password; } public function setPassword($password) { $this->_password = $password; } public function getTypeConnection() { return $this->_typeConnection; } public function setTypeConnection($typeConnection) { $this->_typeConnection = $typeConnection; } public function getPort() { return $this->_port; } public function setPort($port) { $this->_port = $port; } function getIsConnected() { return $this->_isConnected; } function setIsConnected($isConnected) { $this->_isConnected = $isConnected; } /** * Retorna a conexão corrente * @return stream */ public function connect() { $this->_connection = ftp_connect($this->getHost(), $this->getPort(), 120); ftp_set_option($this->_connection, FTP_USEPASVADDRESS, false); if( $this->_connection ){ //faz o login no host especificado $this->login(); } return $this->_connection; } /** * Efetua login no HOST especificado * @return boolean */ private function login() { $res = @ftp_login($this->_connection, $this->_userName, $this->_password); if( $res ){ $this->_isConnected = true; return true; } return false; } /** * Seta o modo de conexão: ATIVA ou PASSIVA * @param bool $modPasv * @return boolean */ protected function setModPasv($modPasv) { return ftp_pasv($this->_connection, $modPasv); } private function setOption($option) { return ftp_set_option($this->_connection, $option, true); } /** * Envia um arquivo para o servidor * @param type $localFile * @param type $remoteFile */ public function putFile($localFile, $remoteFile) { if( $this->getConnection() != null ){ ftp_put($this->getConnection(), $remoteFile, $localFile, FTP_BINARY); } } /** * Faz o download de um arquivo do servidor * @param type $remoteFile * @param type $localFile * @return boolean */ public function getFile($remoteFile, $localFile) { if( $this->getIsConnected() != null ){ @$ret = ftp_nb_get($this->getConnection(), $localFile, $remoteFile, FTP_BINARY); while( $ret == FTP_MOREDATA ){ $ret = ftp_nb_continue($this->getConnection()); } if( $ret != FTP_FINISHED ){ return false; } return true; } return false; } /** * Altera o diretório atual para o diretório passado por parâmetro * @param string $dir * @return boolean */ public function changeDirectory($dir) { if( $this->getConnection() != null ){ return @ftp_chdir($this->getConnection(), $dir); } } /** * Lista os arquivos do diretório corrente * @return array */ public function listFilesInDirectory() { if( $this->getConnection() != null ){ return @ftp_nlist($this->getConnection(), '.'); // return ftp_rawlist($this->getConnection(), ftp_pwd($this->getConnection()), true); } } /** * Fecha a conexão FTP aberta */ public function closeConnection() { ftp_close($this->getConnection()); } public function getLastModifiedFile($file) { return ftp_mdtm($this->getConnection(), $file); } public function getSizeFile($file) { return ftp_size($this->getConnection(), $file); } }
💾 保存文件
← 返回文件管理器