function testTelnetClientBSD() { $TelnetClient = new TelnetClient("65.38.4.218"); // Try to connect $conn = $TelnetClient->Connect(); $this->assertTrue($conn, "PHP Telnet client successfully connected to host"); // Try to login with valid password $login = $TelnetClient->Login("telnettest", "password", "login:"******"Password:"******"[telnettest@bsd2 ~]$"); $this->assertTrue($login, "PHP Telnet client successfully log on"); if ($login) { // Send command and wait for response $TelnetClient->Send("whereis php"); $data = $TelnetClient->WaitForString("/usr/local/bin/php"); $this->assertTrue($data, "PHP Telnet client successfully received waitfor string"); // Get all response $TelnetClient->Send("whereis php"); $data = $TelnetClient->ReadAll(); $this->assertTrue($data, "PHP Telnet client successfully received some data ({$data})"); $TelnetClient->Send("ls -al"); $data = $TelnetClient->WaitForString("dfasdfasdfas"); $this->assertFalse($data, "PHP Telnet client successfully not received waitfor string thast not found"); } // Disconnect $this->assertTrue($TelnetClient->Disconnect(), "PHP Telnet client successfully disconnected from server"); }
/** * Connect to telnet * * @return bool */ public function Connect() { $this->SSH = new SSH2(); return $this->SSH->Connect( $this->Options["host"], $this->Options["port"], $this->Options["login"], $this->Options["password"] ); }
/** * Connect to telnet * * @return bool */ public function Connect() { $this->TelnetClient = new TelnetClient($this->Options["host"], $this->Options["port"], $this->Options["timeout"]); if ($this->TelnetClient->Connect()) { if ( $this->Options['login'] && $this->Options['password']) { if ($this->TelnetClient->Login( $this->Options['login'], $this->Options['password'], $this->Options['loginPromt'], $this->Options['passwordPromt'], $this->Options["consolePromt"] ) ) return true; } else return $this->TelnetClient->WaitForString($this->Options["consolePromt"]); } return false; }