[英]Cannot instantiate abstract class Net_SSH2
I am trying to ssh in a solaris server using php. 我正在尝试使用php在solaris服务器中进行ssh。 I have downloaded a ssh2.php package from this link
我已经从此链接下载了ssh2.php软件包
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" . 现在,我收到“致命错误:无法在第4行的D:\\ MySoftwares \\ xampp \\ xampp \\ htdocs \\ connectdas \\ contodas.php中实例化抽象类Net_SSH2” 。 I am a linux person and know little about php classes.
我是Linux人士,对php类了解甚少。 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 有关更多详细信息,请参见http://php.net/manual/en/language.oop5.abstract.php
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 正如我在Net_SSH2中看到的那样,您可以使用工厂方法,但是您应该创建子类并定义Net_SSH2中的所有抽象方法
or use existing class from lib 或使用lib中的现有类
$ssh = Net_SSH2::factory('OpenSSH', $options);
Thanks a lot for your help sir! 非常感谢您的帮助,先生! @Dolbik.
@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.
我下载了另一个Net软件包,该软件包的Net_SSH2类定义更简单,并将其包含在我的代码中。 For your convenience I am providing the package link here - LINK
为方便起见,我在此处提供包裹链接-LINK
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.