I am using below code to transfer files to an SFTP server
use phpseclib3NetSFTP;
$sftp = new SFTP('localhost');
$sftp->login('user', 'password');
error_log($sftp->pwd());
foreach ($fileList as $key => $value) {
$output = $sftp->put("//data//myfile.txt, //sourceFile.txt, SFTP::SOURCE_LOCAL_FILE);
error_log($output);
}
error_log($sftp->getLastError());
// error_log($sftp->getSFTPLastError());
error_log('------------------------------------');
error_log("<pre>" . print_r($sftp->getErrors(), true) . "</pre>");
// error_log("<pre>" . print_r($sftp->getSFTPErrors(), true) . "</pre>");
error_log("<pre>" . print_r($sftp->getLog(), true) . "</pre>");
error_log("<pre>" . print_r($sftp->getSFTPLog(), true) . "</pre>");
which works fine. The only issue I have is that it is not throwing any error messages if it fails (only $output becomes null).
What do I need to change to get proper logging messages or at least responses from the SFTP server in case of any issues?
2
Answers
copying @neubert comment here to show the correct answer to my question:
You can activate logging in
phpseclib
using theenableLog()
method. Additionally, set thelogIdent
property to distinguish the source of the log entries.