Adding a function to previous class to connect with key instead of user/password
<?php
public function loginWithKey($username, $publicKey, $privateKey, $passphrase = null)
{
if (!@ssh2_auth_pubkey_file($this->connection, $username, $publicKey, $privateKey, $passphrase)) {
throw new Exception("Could not authenticate with given keys or passphrase");
}
$this->sftp = @ssh2_sftp($this->connection);
if (!$this->sftp) {
throw new Exception("Could not initialize SFTP subsystem.");
}
}
?>