If I run this script on my workstation (Ubuntu) it results in a directory listing. If I run it on the server (a Red Hat box where it actually belongs) it retrieves an empty string as the result. I cannot for the life of me isolate any reason for this. Any thoughts on why the server can connect, authenticate, and execute the command but get an empty stream?
The script:
require_once "db_bootstrap.php";
require_once MY_PATH . "/includes/classes/SSHConnection.php";
function fnignore($msg) {
echo "fnignore: " . $msg . "\n";
}
function fndebug($msg, $language, $always_display) {
echo "fndebug: " . $msg . "\n";
echo "\t" . $language . "\n";
echo "\t" . $always_display . "\n";
}
function fnmacerror($pkt) {
echo "fnmacerror:\n";
var_dump($pkt);
echo "=== end ===";
}
function fndisconnect($reason, $msg, $language) {
echo "fndisconnect: " . $reason . "\n";
echo "\t" . $msg . "\n";
echo "\t" . $language . "\n";
}
$connection = ssh2_connect(SSHConnection::SSH_DB1_HOST, 22, NULL, array(
"ignore" => "fnignore",
"debug" => "fndebug",
"macerror" => "fnmacerror",
"disconnect" => "fndisconnect"
));
echo "connection:\n";
var_dump($connection);
$auth_result = ssh2_auth_password($connection, SSHConnection::SSH_DB1_USERNAME, SSHConnection::SSH_DB1_PASSWD);
echo "auth_result:\n";
var_dump($auth_result);
$stream = ssh2_exec($connection, "ls -al");
echo "stream:\n";
var_dump($stream);
$output = stream_get_contents($stream, 1000000, 0);
echo "output:\n";
var_dump($output);
The result on the server:
connection:
resource(21) of type (SSH2 Session)
auth_result:
bool(true)
stream:
resource(22) of type (stream)
output:
string(0) ""
GRRRR!!
On my workstation, this is the output:
connection:
resource(21) of type (SSH2 Session)
auth_result:
bool(true)
stream:
resource(22) of type (stream)
output:
string(525) "total 32
drwx------ 2 imagedaemon imagedaemon 4096 Jul 9 20:53 .
drwxr-xr-x. 7 root root 4096 Jul 9 20:52 ..
-rw------- 1 imagedaemon imagedaemon 307 Jul 10 21:22 .bash_history
-rw-r--r-- 1 imagedaemon imagedaemon 18 Apr 23 2012 .bash_logout
-rw-r--r-- 1 imagedaemon imagedaemon 176 Apr 23 2012 .bash_profile
-rw-r--r-- 1 imagedaemon imagedaemon 124 Apr 23 2012 .bashrc
-rw-r--r-- 1 imagedaemon imagedaemon 500 Feb 27 2012 .emacs
-rw-r--r-- 1 imagedaemon imagedaemon 121 Oct 8 2012 .kshrc
"
wtf??