|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2006-07-13 10:32 UTC] pollita@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Nov 01 00:00:01 2025 UTC |
Description: ------------ When I execute command on remote server with 'ssh2_exec' function and executed command is valid, I receive expected result. For example if I execute command 'dir', I receive stream with all directory entries. But if I execute an invalid command, for example 'dirr', I receive empty stream. When I execute same command using my SSH client (I use PuTTY), I receive the following message: '-bash: dirr: command not found' I also tried to use callback functions but without success. Reproduce code: --------------- $Hostname = 'myhost'; $Username = 'myuser'; $Password = 'mypass'; $Output = null; $Methods = array(); $Callbacks = array ('ignore'=>'cbIgnore', 'debug'=>'cbDebug', 'macerror'=>'cbMACError', 'disconnect'=>'cbDisconnect'); //connecting remote server... if (false === $Connection = ssh2_connect($Hostname, 22, $Methods, $Callbacks)) { die ("Unable to connect '$Hostname'.\n"); } else { echo "Done.\n"; } //authenticating user... if (false === ssh2_auth_password($Connection, $Username, $Password)) { die ("Unable to authenticate user.\n"); } //executing command on remote server if (false === $Stream = ssh2_exec($Connection, 'di')) { die ("Unable to execute command on remote server.\n"); } //set blocking mode on a stream stream_set_blocking($Stream, true); //set output string while ($Block = fread($Stream, 8192)) { $Output.= $Block; } fclose ($Stream); echo $Output; // CALLBACK FUNCTIONS function cbIgnore ($message) { die ("IGNORE: $message"); } function cbDebug ($message, $language, $always_display) { die ("DEBUG: $message"); } function cbMACError ($packet) { echo ("MAC_ERROR: $packet"); return true; } function cbDisconnect ($reason, $message, $language) { die ("DISCONNECT: $message"); }