1

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?

jnemecz
  • 3,171
  • 8
  • 41
  • 77

2 Answers2

1

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');

Lee
  • 10,496
  • 4
  • 37
  • 45
  • Yes, I'm including `autoload.php` as is mentioned above. And with namespace class is not loaded too (PHPStorm highlight in phpseclib in `use phpseclib\Net;` that it doesn't know it...). – jnemecz Nov 01 '16 at 13:49
  • have you `composer require phpseclib/phpseclib`? are you sure about `vendors` folder? it's `vendor` by default – Federkun Nov 01 '16 at 13:52
1

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.

neubert
  • 15,947
  • 24
  • 120
  • 212