thephpleague / flysystem-sftp

[READ-ONLY SUBSPLIT] Flysystem Adapter for SFTP

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to get underlying error?

kunicmarko20 opened this issue · comments

write method is returning false and I have no idea why, is there a way to get the error from phplibsec?

Did you find a way to get errors?

hey @slava-basko I ended up extending the SftpAdapter and overwriting write method:

final class SftpAdapter extends \League\Flysystem\Sftp\SftpAdapter
{
    private LoggerInterface $logger;

    /**
     * @param array<string, mixed> $config
     */
    public function __construct(array $config, LoggerInterface $logger)
    {
        parent::__construct($config);
        $this->logger = $logger;
    }

    /**
     * @param string $path
     * @param string $contents
     *
     * @return array<string, mixed>|false
     */
    public function write($path, $contents, Config $config)
    {
        $response = parent::write($path, $contents, $config);

        if ($response === false) {
            $this->logger->error($this->connection->getLastSFTPError());
        }

        return $response;
    }
}

Right now i'm dealing with legacy which don't have PSR logger. But your option makes sense for me. Thanks!