I have been tasked with connecting to a windows based SFTP server that requires a key AND password to connect to it.
I have worked out how to connect with a password or Key, but I can't work out how to do it with both.
Connect via Key:
//connect to server
$connection = ssh2_connect($SSH_ipadd, 22, array('hostkey'=>'ssh-rsa,ssh-dss'));
if(ssh2_auth_pubkey_file($connection, $SSH_user, $SSH_public_key, $SSH_private_key)){
echo "connected successfully.";
}else{
echo "did not connect correctly.";
}
Connect with user/pass:
//connect to server via ssh in preperation for sftp
$connection = ssh2_connect($SSH_ipadd, 22);
//check connectivity
if(ssh2_auth_password($connection, $SSH_user, SSH_Password)){
echo "connected successfully.";
}else{
echo "did not connect correctly.";
}
But i am unsure how to do both at once.
When i attempt to connect to the server with the CLI
ssh -i private.key USER@ip.address.com
It prompts me, after authenticating the key, for a password. Once this has been authenticated it then logs me into the SFTP server.
How would I use PHP to authenticate against this type of service and then upload files etc.?