0

大家好,我需要一个超级简单的功能,并从安装了 SSH2 扩展的 Web 服务器发送 SSH 命令

这是我现在使用的,但是 SSH2 很烂,无法安装

<?php
$method = $_GET['method'];
$command = $_GET['command'];
$serverusername = $_GET['serverusername'];
$serverip = $_GET['serverip'];
$serverpassword = $_GET['serverpassword'];
$serverport = $_GET['serverport'];

if(!($con = ssh2_connect($serverip, $serverport))) die("Failed connecting to backend server.");
if(!ssh2_auth_password($con, $serverusername, $serverpassword)) die("Failed connecting to backend server.");
ssh2_exec($con, $command);

echo "Command sent";
?>

我能得到类似于接受所有这些变量的东西吗

$method = $_GET['method'];
$command = $_GET['command'];
$serverusername = $_GET['serverusername'];
$serverip = $_GET['serverip'];
$serverpassword = $_GET['serverpassword'];
$serverport = $_GET['serverport'];
4

1 回答 1

2

使用 这个库

像这样使用它:

$ssh = new Net_SSH2('www.domain.tld');
if (!$ssh->login('username', 'password')) {
    exit('Login Failed');
}

echo $ssh->exec('pwd');
echo $ssh->exec('ls -la');
?>
于 2013-05-30T05:35:46.340 回答