connection = ssh2_connect($ip, $port, array('hostkey'=>'ssh-rsa')); if (!ssh2_auth_pubkey_file($this->connection, 'root', $publicKeyPath , $privateKeyPath, $privateKeyPassword)) throw new Exception("Authentification par clé loupée"); } public function send_file($localPath,$remotePath,$permissions = 0755){ return ssh2_scp_send($this->connection, $localPath, $remotePath,$permissions); } public function send_stream($stream,$remotePath,$permissions = 0755){ $tempPath = File::temp().SLASH.sha1(rand(0,1000)); file_put_contents($tempPath, $stream); $return = $this->send_file($tempPath,$remotePath); unlink($tempPath); return $return; } public function execute($command){ $stream = ssh2_exec($this->connection, $command); $errorStream = ssh2_fetch_stream($stream, SSH2_STREAM_STDERR); stream_set_blocking($errorStream, true); stream_set_blocking($stream, true); $error = stream_get_contents($errorStream); $response = stream_get_contents($stream); if(!empty($error)){ $response = $error; } fclose($errorStream); fclose($stream); return $response; } public static function format_output($output){ $output = nl2br($output); //$output = str_replace('', 'blue ?', $output); $output = str_replace('', '', $output); $output = str_replace('', '', $output); $output = str_replace('', '', $output); $output = str_replace('', '', $output); $output = str_replace('', '', $output); return $output; } public function disconnect(){ ssh2_disconnect ($this->connection ); } } ?>