John Davidson

php - 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('');
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 ?


My Answer:
>login('username', 'password')) {_ exit('Login Failed'); }_ $ssh->setTimeout(10);_ $ssh->exec('cd /path/to/files/ && ls -l');_ $files = $ssh->exec('ls -l');_ $fileList = explode("\n", $files);_ foreach ($fileList as $file) { echo $file . "\n"; }_ $ssh->disconnect();_This code will list the files in the specified directory and then loop through each file, echoing the filename.

Rate this post

5 of 5 based on 3444 votes


© 2024 - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us