Support the ongoing development of Laravel.io →
Configuration Authentication Requests
Last updated 2 years ago.
0

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:

http://laravel.com/docs/ssh

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

Last updated 2 years ago.
0

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

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

maleeb maleeb Joined 17 Apr 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.