0

Hey everyone I need a function that is super simple and sends SSH commands from my Web Server with SSH2 extension installed

This is what I use now but SSH2 sucks and is impossible to install

<?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";
?>

Can I get something similar to that that accepts all these variables

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

1 Answer 1

2

Use This library

use it like:

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

echo $ssh->exec('pwd');
echo $ssh->exec('ls -la');
?>
Sign up to request clarification or add additional context in comments.

6 Comments

Well I am running WampServer on a Windows system, would that still work?
Why not!! if u are ssh(ing) on a linux machine it would work!
Can you help me or no? It's not a linux machine... I have been told you can do this through fsock
Wait..Ypu are ona a WAMP machine. Ypu want to ssh a Linux machine?? OR you are on wamp and want to ssh wamp machine?
The library sankalp mentioned should work on ANY PHP install, be it on Linux, Windows, Mac, Mac OS 9, whatever. Uses fsockopen, as you noted it'd have to, and PHP code to format everything appropriately. Try it out.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.