I’ve gotten some awesome help here, and am having a hard time with another piece of a project. For part of it, I’m writing a small ssh library, to ssh out, run a command, capture the output, and return it to the user. I’m unable to get all of the output of the command. I can get most of it, but I’m missing the MOTD and am not getting the rest of the output. I’m thinking the problem is in my logic and unfamiliarity with the commands (even after looking at the php man).
Here’s what I have, and it does work connection wise, and the commands I pass in do run, but I’m only getting partial output back. Should I be getting more than 4096 bytes in the fread? That seems like an awful lot. Do I need to set stream blocking to true? Btw, I set the timeouts way up for this, expecting large outputs for some of my commands.
[CODE]
if(!($con = ssh2_connect(jumpServer, 22))){
echo “fail: unable to establish connection to $jumpServern”;
} else {
// try to authenticate w/ user and secret pass
if(!ssh2_auth_password($con, $username, $password)) {
echo “fail: unable to authenticate user $usernamen”;
} else {
// debug
//echo “okay: logged in…n”;
//echo $command.”n”;
// execute a command
if (!($stream = ssh2_exec($con, $command))) {
echo “fail: unable to execute command $commandn”;
} else {
// collect output from command
stream_set_blocking($stream, true);
$data = “”;
while ($buf = fread($stream,4096)) {
$data .= $buf.”n<br />”;
}
fclose($stream);
if ($data != “”){
echo $data;
}else{
echo “data: “. $data . ” but NO DATA”;
}
return $data;
}
}
}