Hey maleeb,
Any reason why you are using that library instead of using Laravel 4.1's built in SSH functionality (probably extends the SSH2 library anyway), documentation for executing commands and getting the console output can be found here:
EDIT:- Sorry, my bad, I see that you're trying to run this command from a server NOT using Laravel...
Try this:
<?php
include('Net/SSH2.php');
$ssh = new Net_SSH2('www.domain.tld');
if (!$ssh->login('username', 'password')) {
exit('Login Failed');
}
if (!($stream = ssh2_exec($con, "ls -al" ))) {
echo "fail: unable to execute command\n";
} else {
// collect returning data from command
stream_set_blocking($stream, true);
$data = "";
while ($buf = fread($stream,4096)) {
$data .= $buf;
}
fclose($stream);
}
Hope this helps, Cheers, Bobby
Hey thx for your help bobsta63, if forgot to include ' include('Net/SSH2.php'); '.
And:
In contrast to
if (!($stream = ssh2_exec($con, "ls -al" ))) {
i use
if (!($stream = $con->exec("ls -al")
then i don't need this anymore, i can print out $stream directly
stream_set_blocking($stream, true);
$data = "";
while ($buf = fread($stream,4096)) {
$data .= $buf;
}
fclose($stream);
Cheers, Ali
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community