I answered that question three years ago and I would still give that same answer.
It's kinda rare that SFTP servers use both password and publickey
authentication. My guess would be that what you most likely have is a
password protected private key. If so you can login thusly:
<?php
include('Net/SFTP.php');
include('Crypt/RSA.php');
$sftp = new Net_SFTP('www.domain.tld');
$key = new Crypt_RSA();
$key->setPassword('whatever');
$key->loadKey(file_get_contents('privatekey'));
if (!$sftp->login('username', $key)) {
exit('Login Failed');
}
print_r($sftp->nlist());
?>
If indeed your server truly is doing both the following should work:
<?php
include('Net/SFTP.php');
include('Crypt/RSA.php');
$sftp = new Net_SFTP('www.domain.tld');
$key = new Crypt_RSA();
$key->setPassword('whatever');
$key->loadKey(file_get_contents('privatekey'));
if (!$sftp->login('username', $key) && !$sftp->login('username', 'password')) {
exit('Login Failed');
}
print_r($sftp->nlist());
?>
Note that that's for the 1.0 version. If you're using the 2.0 version the code will need to be changed somewhat. Since you haven't posted your own code it's impossible to know what version you're using.
Also, in reviewing that 3.5 year old post... it looks like there were issues but those issues should now be fixed. I've done multi factor auth myself with phpseclib without issue. Do you have reason to believe it doesn't work?
edit: for 2.0 you'd need to do this:
For 2.0 you'll need to do this:
$sftp = new SFTP('www.domain.tld');
$key = new RSA();
//$key->setPassword('whatever');
$key->loadKey(file_get_contents('privatekey'));
if (!$sftp->login('username', $key) && !$sftp->login('username', 'password')) {
exit('Login Failed');
}
print_r($sftp->nlist());