Joe Huss

Generation

class from descriptionThu, 19 Jan 2023

create an ssh class for multiplexing ssh connections and running commands on them in a queue.

<?php class SSH { private $conn; private $host; private $port; private $username; private $password; private $commands; public function __construct($host, $port, $username, $password) { $this->conn = ssh2_connect($host, $port); $this->host = $host; $this->port = $port; $this->username = $username; $this->password = $password; $this->commands = []; } public function addCommand($command) { $this->commands[] = $command; } public function execute() { array_unshift($this->commands, 'export TERM=xterm;'); $command = implode('', $this->commands); return ssh2_exec($this->conn, $command); } } $ssh = new SSH('192.168.1.1', 22, 'root', 'password');

Questions about programming?Chat with your personal AI assistant