phpsftpphpseclib

How can I get the logging from phpseclib and SFTP?


I am using below code to transfer files to an SFTP server

use phpseclib3\Net\SFTP;

$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?


Solution

  • copying @neubert comment here to show the correct answer to my question:

    you'd need to do define('NET_SFTP_LOGGING', 2) at the top of the file for that to work.