Reputation: 34
I placed the phpseclib
files in my application/third_party
folder, I have included the path in my controller as shown below
set_include_path(get_include_path() . PATH_SEPARATOR . 'third_party/phpseclib/Net/SSH2.php');
But I cannot create an instance of that class. Getting an error as
class ssh2 not found
What's the most appropriate way to use phpseclib
?
Upvotes: 0
Views: 2094
Reputation: 34
After doing a lot of research, I finally found my problem. The problem was - i didn't add include the path after setting the set_include_path. Here is what I did-
1. I placed phpseclib files in my application/third_party folder.
2. In my controller, I set the include path as set_include_path(get_include_path() . PATH_SEPARATOR . 'phpseclib');
3. After setting the path, I included the path as include_once(APPPATH.'third_party/phpseclib/Net/SFTP.php');
4. Now I can create my instance as $sftp = new Net_SFTP('your-host');
5. And connect my server as $sftp->login('user-name', 'password')
Upvotes: 1
Reputation: 1458
On github.com there are two branches (in addition to the master branch) - 1.0 and 2.0. 2.0 is namespaced so to call that you'd need to do \phpseclib\Net\SSH2.
If you downloaded the zip file from phpseclib.sourceforge.net then you're running the 1.0 branch. If that's what you're running you'll need to update the include path. eg.
set_include_path(get_include_path() . PATH_SEPARATOR . 'phpseclib');
If you're running the 2.0 branch (or master branch) you'll need to use an auto loader. Example:
<?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();
Upvotes: 0