Reputation: 2509
after creating a small library to send and receive files via SFTP using ssh2_sftp method I've found that the server which I have to connect to has ssh connection disabled and I can only connect through SFTP.
The server connection works well under the command line using sftp command, but ssh sends me a "This service allows sftp connections only."
So as ssh2_sftp needs a previous ssh connection in order to work, I don't know which library or how to do things in order to connect to a SFTP server with SFTP authentication.
Does phpseclib use a different authentication approach than ssh2_ftp?
Any ideas? Thanks.
Upvotes: 3
Views: 6890
Reputation:
99% of keyboard-interactive authentications just prompt for a password. phpseclib, a pure PHP SFTP implementation, tries submitting the password via keyboard-interactive if password authentication fails. Example of how to use it:
<?php
include('Net/SFTP.php');
$sftp = new Net_SFTP('www.domain.tld');
if (!$sftp->login('username', 'password')) {
exit('Login Failed');
}
// outputs the contents of filename.remote to the screen
echo $sftp->get('filename.remote');
?>
Upvotes: 3
Reputation: 2509
Yes, you're completely right @arkascha... after a little research I found the reason.
When I was testing my code against my own server, it worked, and against the other server it was failing so I thought it was because ssh shell connection was disabled.
After asking both servers for the allowed auth methods (using ssh2_auth_none), I got what was wrong:
My server:
[0] => publickey
[1] => password
The other server (the one that was failing):
[0] => publickey
[1] => gssapi-keyex
[2] => gssapi-with-mic
[3] => keyboard-interactive
as it doesn't allow password, it is failing. That's it...
I apologize for making you waste your time...Thanks a lot
Upvotes: 1