✏️ 正在编辑: Sftp.php
路径:
/srv/systems_dir/biblioteca_yuppie/library/Yuppie/Sftp.php
提示:
您可以编辑任何文件(包括二进制文件),但请注意不当修改可能导致文件损坏。
<?php use phpseclib3\Net\SFTP; class Yuppie_Sftp { private $_connection; private $_host; private $_userName; private $_password; private $_port; private $_isConnected = false; /** * Abre uma conexao FTP para o host especificado * @param string $_host * @param string $_userName * @param string $_password * @param int $port */ function __construct($_host, $_userName, $_password, $_port = 22) { $this->_host = $_host; $this->_userName = $_userName; $this->_password = $_password; $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 = new SFTP($this->getHost()); 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 = $this->_connection->login($this->_userName, $this->_password); if( $res ){ $this->_isConnected = true; return true; } return false; } /** * 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 ){ return $this->_connection->get($remoteFile, $localFile); } 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 $this->_connection->chdir($dir); } } /** * Lista os arquivos do diretório corrente * @return array */ public function listFilesInDirectory() { if( $this->getConnection() != null ){ return $this->_connection->nlist(); } } /** * Fecha a conexão FTP aberta */ public function closeConnection() { $this->_connection = null; } public function getLastModifiedFile($file) { return $this->_connection->filemtime($file); } public function getSizeFile($file) { return $this->_connection->filesize($file); } }
💾 保存文件
← 返回文件管理器