note 53645 added to function.ssh2-shell

From: Date: Wed, 08 Jun 2005 08:38:59 +0000
Subject: note 53645 added to function.ssh2-shell
Groups: php.notes 
Request: Send a blank email to php-notes+get-90101@lists.php.net to get a copy of this message
// Connection to SSH server echo "Connexion SSH "; if (!($resource=@ssh2_connect("192.168.0.1"))) { echo "[FAILED]<br />"; exit(1); } echo "[OK]<br />"; // Authentification by login/passwd echo "Authentification "; if (!@ssh2_auth_password($resource,"root","your_password")) { echo "[FAILED]<br />"; exit(1); } echo "[OK]<br />"; // We need a shell echo "Shell stdio "; if (!($stdio = @ssh2_shell($resource,"xterm"))) { echo "[FAILED]<br />"; exit(1); } echo "[OK]<br />"; // Execution of any command // Be careful to add an '\n' at the end of the command $command = "/bin/ls /tmp\n"; fwrite($stdio,$command); // IMPORTANT // For some obscur reasons, just after ur command, u need to make a sleep to be sure, that the command has reached the server and is running sleep(1); // Then u can fetch the stream to see what happens on stdio while($line = fgets($stdio)) { flush(); echo $line."<br />"; } // It's always cleaner to close all stream fclose($stdio); I truly hope i'll help someone :) ---- Manual Page -- http://www.php.net/manual/en/function.ssh2-shell.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+53645 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+53645&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+53645&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+53645&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+53645&report=yes&reason=useless Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+53645&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+53645&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#90101) next »