0

I am new to php and phpseclib.

I'am planning to write a SSH client as part of my project in php. I'am using phpseclib library.

In my project the public key will be uploaded to a server (router) which only supports openSSH and Putty key format (public key).

I've created the key pairs using puttykeygen. I wrote a SSH client in php. But after showing loading for some time it shows : NOTE:I don't think it because of the limited execution time(30 sec)

Fatal error: Maximum execution time of 30 seconds exceeded in C:\xampp\htdocs\pages\Net\SSH2.php on line 2699

My code:

<?php
include('Net/SSH2.php');
include('Crypt/RSA.php');

$ssh = new Net_SSH2('remoteip');
$key = new Crypt_RSA();
$key->loadKey(file_get_contents('sshprivatekeyfile'));
if (!$ssh->login('admin', $key)) {
print_r($ssh->getError());
exit('Login Failed');
}

echo $ssh->exec('show clients');/any router commands/*
?>
  • I see you edited your question which partially invalidates my answer. Anyway, idk what `show clients` is supposed to do. Maybe it's expecting user input or maybe something else is going on. Can you do `$ssh->setTImeout(5)` before the `$ssh->exec()` and post what you get back as your output? – neubert Mar 16 '15 at 18:45
  • @ neubert thanx for the replay.normaly 'show clients' will return a table which contain client information such as mac ,ip uploaded data downloaded data etc..(in putty and linux openssh client) . But when I tried as suggested by you(including setTimeout(4)) it shows nothing. I also tried to get the logs using getLogs() it shows(in log) Failed to get terminal attributes – user4675160 Mar 17 '15 at 04:24
  • You might need to do `$ssh->enablePTY()`. Seeing the logs could provide more insight as well if you could put them on pastebin.com and then edit your post to include the pastebin.com link that could help. – neubert Mar 17 '15 at 15:20
  • @neubert now I tried using $ssh->enablePTY() now the $ssh->exec() returns one(1) . How can i get the data? – user4675160 Mar 19 '15 at 10:13
  • Do `echo $ssh->read()`. – neubert Mar 19 '15 at 12:34

2 Answers2

0

check this LINK

extend the maximum execution time like this:

ini_set('max_execution_time', 300); //300 seconds

Community
  • 1
  • 1
Geo Tom
  • 270
  • 3
  • 16
0

Do ping 192.168.10.1 on the CLI (Linux). Does it end? It doesn't for me. It just keeps sending data forever and ever. So that's probably why it's timing out for you. Because the ping command isn't ever actually ending.

There are two solutions.

  1. Do ping -c 4 192.168.10.1
  2. Do $ssh->setTimeout(4) before $ssh->exec().
neubert
  • 15,947
  • 24
  • 120
  • 212