Class 'Net_SSH2' 在...中找不到 'Net_SSH2' 使用 phpseclib 时
Class 'Net_SSH2' not found in... when using phpseclib
我正在尝试使用 phpseclib 在我的服务器上 运行 一些 ssh 命令。尝试下面,我得到 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 上有两个分支(除了主分支)- 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 分支(或主分支),则需要使用自动加载程序。示例:
<?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();
我正在尝试使用 phpseclib 在我的服务器上 运行 一些 ssh 命令。尝试下面,我得到 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 上有两个分支(除了主分支)- 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 分支(或主分支),则需要使用自动加载程序。示例:
<?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();