[英]Class 'Net_SSH2' not found in… when using phpseclib
我正在嘗試使用phpseclib在服務器上運行一些ssh命令。 嘗試下面的操作,我得到Class 'Net_SSH2' not found in....
中Class 'Net_SSH2' not found in....
這似乎表明phpseclib
沒有正確加載,但是回顯顯示包括正在運行。
我在這里做錯了什么?
php
<?php
ini_set('display_errors',1);
ini_set('display_startup_errors',1);
error_reporting(-1);
$thepath = $_SERVER['DOCUMENT_ROOT']. '/inc/phpseclib/Net/SSH2.php';
echo '<strong>Full include path:</strong> '. $thepath;
include ($thepath);
$included_files = get_included_files();
foreach ($included_files as $filename) {
echo "<br><strong>Included file:</strong>$filename";
}
$ssh = new Net_SSH2('xx.xx.x.xx.x'); // server's ip address
if (!$ssh->login('username', 'password')) { // filled in correctly
exit('Login Failed');
}
echo $ssh->exec('pwd');
echo $ssh->exec('ls -la');
?>
Done.
Full include path: /var/chroot/home/content/08/555555555/html/inc/phpseclib/Net/SSH2.php
Included file:/home/content/08/555555555/html/TeamBoard/deploy.php
Included file:/home/content/08/555555555/html/inc/phpseclib/Net/SSH2.php
Fatal error: Class 'Net_SSH2' not found in /home/content/08/555555555/html/TeamBoard/deploy.php on line 25
在github.com上有兩個分支(除了master分支之外)-1.0和2.0。 2.0具有命名空間,因此調用它需要執行\\ phpseclib \\ Net \\ SSH2。
如果您從phpseclib.sourceforge.net下載了zip文件,那么您正在運行1.0分支。 如果這就是您要運行的內容,則需要更新包含路徑。 例如。
set_include_path(get_include_path() . PATH_SEPARATOR . 'phpseclib');
如果您正在運行2.0分支(或master分支),則需要使用自動加載程序。 例:
<?php
// https://raw.githubusercontent.com/composer/composer/master/src/Composer/Autoload/ClassLoader.php
include('autoloader.php');
$loader = new \Composer\Autoload\ClassLoader();
$loader->addPsr4('phpseclib\\', __DIR__.'/phpseclib');
$loader->register();
use \phpseclib\Crypt\RSA;
$rsa = new RSA();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.