Tom
Tom

Reputation: 1618

phpseclib-SSH2 stream results from command?

I'm using phpseclib to ssh into a remote device and download files. This works and when it completes it shows a list of files it has downloaded.

However I'd like it to show each filename as it's downloaded.

The code I'm using is:

    $ssh = new Net_SSH2('192.168.0.1');
    if (!$ssh->login('user', 'password')) {
        exit('Login Failed');
    } 
    function output($str) {
        echo "$str";
    }


    $cmd = "getfiles";
    $res = $ssh->exec($cmd, "output"); 

If I use putty and SSH into the remote device and then run getfiles it will show each filename on a new line as it is handled.

phpseclib seems to just show the final result, not the live progress.

Is there anyway to make it show the live progress ?

Thanks

Upvotes: 1

Views: 526

Answers (1)

Tom
Tom

Reputation: 1618

I've got this working by updating the output function as follows.

function output($str) {
    flush();  ob_flush();
    echo "$str<br>";
}

Now the output is shown on a new line.

Upvotes: 1

Related Questions