Cannot load phpseclib library installed with composer in CakePHP application

1.6k Views Asked by At

I would like to use phpseclib librabry in my CakePHP 2.8 application. After installation of all dependencies into app/Vendor directory I am trying to try phpseclib installation.

But I am not able to load library:

include('Net/SFTP.php');
$sftp = new Net_SFTP('127.0.0.1');

but this error occures:

Error: Class 'Net_SFTP' not found

In AppController I'm loading auto-generated include and I thought it must be done:

require_once ROOT . DS . 'vendors' . DS . 'autoload.php';

What am I missing?

2

There are 2 best solutions below

2
Lee On

If your using composer then you just need to include composers autoloader. You don't need to include the specific libraries (thats the point of composers autoloader).

If you look at the source code of the library you'll notice that it's namespaced (https://github.com/phpseclib/phpseclib/blob/2.0.4/phpseclib/Net/SFTP.php#L38). So you need either import the namespace with the use statement, or:

$sftp = new phpseclib\Net\SFTP('127.0.0.1');

0
neubert On

If you did composer require phpseclib/phpseclib instead of composer require phpseclib/phpseclib:~1.0 you're using 2.0. Net_SFTP is only in the 1.0 branch. In the 2.0 branch it's \phpseclib\Net\SFTP.

http://phpseclib.sourceforge.net/2.0.html elaborates.