SSH to Cisco ASA

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Slowfib
Forum Newbie
Posts: 5
Joined: Tue Oct 31, 2006 11:23 am

SSH to Cisco ASA

Post by Slowfib »

I've been working on a script on and off for a while to SSH to a Cisco ASA and run some commands. I'm able to login to the device just fine, but I haven't had any luck getting any results back from my commands.

I'm not sure I'm using the stream_set_blocking function correctly because sometimes I get a bit of data if I run the script twice and alternative between setting stream_set_blocking to true or false. After I get 1 line sometimes, the connection seems to just drop after that.

Code: Select all

$ssh = ssh2_connect($ip, 22);
if (!ssh2_auth_password($ssh, $username, $password)) {
   exit('Login Failed');
}
$vpncmd = "?";
$stream = ssh2_exec($ssh, $vpncmd) or die("error");
stream_set_blocking($stream, false);
$data = "";
while ($buf = fread($stream, 4096)) {
   $data .= $buf;
}
fclose($stream);
echo $data;
If anyone has any suggestions, I'd really appreciate it. Or if there is a way to display SSH's debug info on the connection status and could troubleshoot that.

Or if there's even some way I can push all my commands through Putty.exe :)

Thank you!
Post Reply