0

I am trying to pass a form variable to phpseclib ssh as a hostname. Something like this:

<form action="test.php" method="post">
IP OR HOSTNAME: <input type="text" name="ipaddr">

<?php
$ipaddr = $_POST["ipaddr"];
$ssh = new ssh2('$ipaddr');
if (!$ssh->login('username', 'password')) {
    exit('Login Failed');
}
echo $ssh->exec('command1');
echo $ssh->exec('command2');
?>

Doesn't appear to be working. What am I missing?

multipl3x_
  • 3
  • 1
  • 4
  • I'm not sure what ssh2 library you're using, but this might help: http://stackoverflow.com/questions/6270419/how-to-execute-ssh-commands-via-php -- otherwise, there's PHP's `ssh2_*` functions: http://us2.php.net/manual/en/function.ssh2-auth-password.php – Rob W Jun 28 '13 at 17:17

1 Answers1

0

If you're using phpseclib you should be doing this:

$ssh = new Net_SSH2($ipaddr);

Instead of what you are doing:

$ssh = new ssh2('$ipaddr');

Note how it's Net_SSH2 instead of ssh2. Also note how $ipaddr isn't in single quotes. The fact that that's unnecessary not withstanding variables aren't replaced when single quotes are used.

neubert
  • 15,947
  • 24
  • 120
  • 212