SSH2 + PHP

Whenever I try and execute
[php]if (!($stream = ssh2_exec($con, “cd $dir; screen -S creative java -Xmx500M -Xms500M -jar spigot.jar” ))) {[/php]
it keeps returning with ‘Must be connected to a terminal.’ which I can’t seem to get around.
How do I get around/fix this?

Thanks

Well, you don’t have the connection created. You first connect, then exec commands, then disconnect.
Here is a sample taken from the manual at php.net… Link is below…

<?php $connection = ssh2_connect('shell.example.com', 22); ssh2_auth_password($connection, 'username', 'password'); $stream = ssh2_exec($connection, '/usr/local/bin/php -i'); ?>

You use fclose($connection); to disconnect it. (ssh’s connections are treated as “streams”, I think!)

More info: http://php.net/manual/en/function.ssh2-exec.php

Sponsor our Newsletter | Privacy Policy | Terms of Service