发送SSH命令PHP

时间:2013-05-30 05:32:01

标签: php ssh

嘿大家我需要一个超级简单的功能,并从安装了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'];

1 个答案:

答案 0 :(得分:2)

使用 This library

使用它像:     

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

echo $ssh->exec('pwd');
echo $ssh->exec('ls -la');
?>