SSH connect using PHP

I am trying to connect to the server through SSHusing the code below:

include('Net/SSH2.php'); 
$ssh = new Net_SSH2('mydomain.com'); 
if (!$ssh->login('xxxx', 'xxxx')) { 
   exit('Login Failed'); 
}else{ 
   echo "connected"; 
} 
echo $ssh->exec('pwd');

It says connectedbut does not show output for code echo $ssh->exec('pwd');

Why?

MESSAGES FOR LOG

-> NET_SSH2_MSG_CHANNEL_REQUEST (since last: 0.0002, network: 0s)
00000000  00:00:00:00:00:00:00:04:65:78:65:63:01:00:00:00  ........exec....
00000010  03:64:69:72                                      .dir

<- NET_SSH2_MSG_CHANNEL_FAILURE (since last: 0.0611, network: 0.0001s)
00000000  00:00:00:00                                      ....
+4
source share
1 answer

you can use the 'ssh2_connect' function in php. After using 'ssh2_exec' and copy the result to $ var.

at the end you can use 'stream_get_contents ($ var);' to return the ssh result command

Remember to use the php "sleep (1)" function to prevent errors after running the ssh command.

'ssh2_exec' is a php resource.

0

Source: https://habr.com/ru/post/1621262/


All Articles