Learn
composer require phpseclib/phpseclib:~3.0
require_once('vendor/autoload.php');
use phpseclib3\Net\SFTP;
// The credentials of the SFTP server
$host = 'hostname';
$user = 'username';
$password = 'password';
// Establish the connection
$sftp = new SFTP($host);
$sftp->login($user, $password);
// Loop through the files and show the file name on a new line
foreach ($sftp->nlist() as $key => $fileName) {
echo $fileName . PHP_EOL;
}
// Get the contents of a file
echo $sftp->get('filename');
// Put contents of a file
$sftp->put('remote_file', 'local_file_content');
// Delete file
$sftp->delete('filename');