I need to use FTP(S) and SFTP in my extension to receive and send files. I got FTP(S) to work with no problems whatsoever (using Varien_Io_Ftp), but I'm struggling with SFTP.
The problem is that there is an error that occurs only sporadically. Sometimes everything works as expected and the file is transferred, but sometimes it just refuses to connect to the server at all (Error: Unable to open SFTP connection as user@localhost
).
I have traced it down to the file lib/phpseclib/Net/SSH2.php
in line 1274 (getting response to 'ssh-userauth' packet), which returns false
.
I'm fairly certain that the problem is not the SSH/SFTP server, because I can connect via CLI (using both ssh
and sftp
) every time.
Now what can I do to make this work reliably? I don't think updating the phpseclib is an option since it's part of / shipped with Magento core, right? I'm using Magento 1.9.3.2 by the way.
Edit: Here is what I do with the SFTP class, if that helps:
$this->connection = new Varien_Io_Sftp();
$args = array(
'host' => $host,
'username' => $user,
'password' => $password,
);
$this->connection->open($args);