🚀 This code is created to load the PHPseclib library in CodeIgniter. It can also be utilized with other libraries.
Developed due to the lack of SSH or CMD access, preventing the installation of libraries using Composer, so we have to install the library manually. As a workaround, we manually download the library from GitHub.
In this case, we are using PHPSeclib version 2: PHPSeclib 2.0
-
Download Library
- Download the library from the provided link.
-
Create Folder
- Create a folder named
third_party
within theapplication
folder.
- Create a folder named
-
Organize Library
- Create a folder named
phpseclib
withinthird_party
and move the downloaded files there. The folder structure should be "/application/third_party/phpseclib/"
- Create a folder named
-
Call Library in Controller
- In your Controller, include all the necessary library files as they are interdependent.
require_once APPPATH . 'third_party/phpseclib/phpseclib/Net/SSH2.php'; require_once APPPATH . 'third_party/phpseclib/phpseclib/Crypt/Base.php'; require_once APPPATH . 'third_party/phpseclib/phpseclib/Net/SSH2.php'; require_once APPPATH . 'third_party/phpseclib/phpseclib/Crypt/Base.php'; require_once APPPATH . 'third_party/phpseclib/phpseclib/Crypt/RC4.php'; require_once APPPATH . 'third_party/phpseclib/phpseclib/Crypt/Rijndael.php'; require_once APPPATH . 'third_party/phpseclib/phpseclib/Crypt/Twofish.php'; require_once APPPATH . 'third_party/phpseclib/phpseclib/Crypt/Blowfish.php'; require_once APPPATH . 'third_party/phpseclib/phpseclib/Crypt/DES.php'; require_once APPPATH . 'third_party/phpseclib/phpseclib/Crypt/TripleDES.php'; require_once APPPATH . 'third_party/phpseclib/phpseclib/Crypt/Random.php'; require_once APPPATH . 'third_party/phpseclib/phpseclib/Crypt/Hash.php'; require_once APPPATH . 'third_party/phpseclib/phpseclib/Crypt/RC2.php'; require_once APPPATH . 'third_party/phpseclib/phpseclib/Crypt/AES.php'; require_once APPPATH . 'third_party/phpseclib/phpseclib/Math/BigInteger.php'; require_once APPPATH . 'third_party/phpseclib/phpseclib/Net/SFTP.php';
-
Utilize PHPSeclib in Controller
- Call the PHPSeclib class you want to use. In this example, we are using SFTP.
$sftp = new \phpseclib\Net\SFTP('https://yoursftpdestination'); if ($sftp->login('yourusername', 'yourpassword')) { echo "Success connect using SFTP"; }
Feel free to adapt the code based on your requirements. Happy coding! 🎉