I am trying to change an old piece of code that uses ftp_login()
with a username and password to instead use an ssh key I have installed on the server.
I've found phpseclib which seems to be able to do that, but it requires I rewrite the entire section of code (e.g. ftp_put()
would have to become $sftp->put()
) and install that library. Ideally I would only need to replace ftp_login()
and nothing would need to be installed.
I haven't come across anything like that in my research, but that hardly means it doesn't exist. Does anyone know of a key based alternative to ftp_login()
that isn't phpseclib?
PHP ftp_*
functions implement FTP protocol. A public key authentication is used with SFTP protocol (based on SSH).
The SFTP is a completely different protocol than the FTP. So there's absolutely no way, you can use the ftp_*
functions for the SFTP (let alone for the public key authentication).
For the SFTP (even without the public key authentication), you have to use a different set of functions, like phpseclib or PHP SSH2. And that indeed means a complete rewrite of the code.