目前,我面临着一个难题,我在网上找不到任何可以帮助我的东西。
我想通过SSH从服务器连接到另一台服务器以发送指令(第二台服务器管理Wi-Fi授权)。
尽我所能说,我认为问题是因为我们更新了一台服务器。(我不确定这个问题是否已经出现了)。
我来自Windows Server,我想给Linux打电话。
这是脚本:
function executeCommand($command) {
$infoConnection = getInfoConnection();
$out = '';
//The Warning occurs here, impossible to go further
$connection = ssh2_connect($infoConnection["hostname"], 22);
if ($connection === false) {
$error = error_get_last();
throw new Exception("
Error Type : ".$error["type"]."<br/>
Message : ".$error["message"]."<br/>
File : ".$error["file"]."<br/>
Line : ".$error["line"]."<br/>");
}
ssh2_auth_password($connection, $infoConnection["username"], $infoConnection["password"]);
$stdio_stream = ssh2_shell($connection);
sleep(2);
fwrite($stdio_stream,$infoConnection["username"]."\n");
sleep(1);
fwrite($stdio_stream,$infoConnection["password"]."\n");
sleep(1);
fwrite($stdio_stream, $command."\n");
sleep(1);
while($buffer = fgets($stdio_stream)) {
$out .= $buffer;
}
fwrite($stdio_stream, 'exit');
unset($connection);
return $out;
} …
Run Code Online (Sandbox Code Playgroud)