<?php
include('Net/SSH2.php');
$ssh = new Net_SSH2('10.106.240.212');
$ssh->login('Administrator', 'Nbv12345') or die("Login failed");
echo $ssh->exec('powershell.exe');
echo connected;
?>
我正在尝试执行&#39; powershell.exe&#39;使用PHP SSH2。脚本 30秒后超时始终。
我可以通过普通的SSH客户端进行SSH连接
虽然我能够执行像
这样的简单命令dir
如何输入powershell并执行命令?提前谢谢!
答案 0 :(得分:1)
您需要启用PTY或使用交互式shell。例如
<?php
include('Net/SSH2.php');
$ssh = new Net_SSH2('10.106.240.212');
$ssh->login('Administrator', 'Nbv12345') or die("Login failed");
$ssh->write("powershell.exe\n");
$ssh->setTimeout(2);
echo $ssh->read();
//$ssh->write("dir\n");
//$ssh->read('[prompt]');
?>
...或:
<?php
include('Net/SSH2.php');
$ssh = new Net_SSH2('10.106.240.212');
$ssh->login('Administrator', 'Nbv12345') or die("Login failed");
$ssh->enablePTY()
$ssh->exec("powershell.exe\n");
$ssh->setTimeout(2);
echo $ssh->read();
//$ssh->write("command\n");
//$ssh->read('[prompt]');
?>