I am trying to ssh in a solaris server using php. I have downloaded a ssh2.php package from this link
and included it into my code. My code is following
<?php
include 'D:/MySoftwares/xampp/xampp/php/PEAR/Net_SSH2-master/Net/SSH2.php';
$ssh = new Net_SSH2('ip');
if (!$ssh->login('user', 'pass')) {
exit('Login Failed');
}
echo $ssh->exec('pwd');
echo $ssh->exec('ls -ltrh');
?>
Now I am getting "Fatal error: Cannot instantiate abstract class Net_SSH2 in D:\\MySoftwares\\xampp\\xampp\\htdocs\\connectdas\\contodas.php on line 4" . I am a linux person and know little about php classes. Can anyone help me out?
You can't create a instance of abstract class
see http://php.net/manual/en/language.oop5.abstract.php for more details
As i see in Net_SSH2 you can use factory method but you should create child class and define all abstract methods from Net_SSH2
or use existing class from lib
$ssh = Net_SSH2::factory('OpenSSH', $options);
Thanks a lot for your help sir! @Dolbik. I have found another way forward. It was plain and simple. I downloaded another Net package which has simpler class definition of Net_SSH2 and just included it in my code. For your convenience I am providing the package link here - LINK
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.