Pardeep Beniwal
Pardeep Beniwal

Reputation: 63

How to set up phpseclib with composer

I have downloaded phpseclib using composer and it created the path /var/www/html/dom/vendor/phpseclib/phpseclib/phpseclib

Now I am not sure where I include my test.php file to run it. Continuously getting the error " Fatal error: Class 'phpseclib\Net\SSH2' not found in /var/www/html/dom/vendor/phpseclib/phpseclib/phpseclib/Net/SFTP.php on line 50"

My code of test.php is

<?php
set_include_path(get_include_path() . PATH_SEPARATOR . '/phpseclib');
include('Net/SFTP.php');

$sftp = new Net_SFTP('domain');
if (!$sftp->login('user', 'pass')) {
    exit('Login Failed');
}

// outputs the contents of filename.remote to the screen
echo $sftp->get('filename.remote');
// copies filename.remote to filename.local from the SFTP server
//$sftp->get('filename.remote', 'filename.local');

?>

Upvotes: 2

Views: 10623

Answers (2)

lony
lony

Reputation: 7780

Besides the include/require the namespace is also different. Thats the solution for me:

require_once __DIR__ . '/vendor/autoload.php';

$handler = new \phpseclib\Net\SFTP('ftp_host');

if (!$handler->login('ftp_user', 'ftp_password')) {
   exit('FTP login failed');
}

print_r($handler->nlist());

Upvotes: 2

Andreas Linden
Andreas Linden

Reputation: 12721

Composer generates an autoloader. You don't have to care about including things manually. Just do:

include '/var/www/html/dom/vendor/autoload.php';

Upvotes: 4

Related Questions