I need to upload files by SFTP from a PHP script. I think cURL is probably the way, as I have this available on the server.
Has anyone got an example of how to use cURL for SFTP using identity key authentication?
-- EDIT --
I've just noticed that HTTP PUT might be an alternative, but how secure it that?
To authenticate with a private key and certificate using curl, you will need to provide the --key and --cert options to your request. The private key must be decrypted in plain text. The provided certificate must contain the corresponding public key.
Select Open Connection Select SFTP (SSH File Transfer Protocol) for the connection type. Enter server, port (22), username. You can skip password - it will use the SSH key. For SSH Private Key, select Choose... and find the save location of your file.
curl supports the SCP and SFTP protocols if built with a prerequisite 3rd party library: libssh2, libssh or wolfSSH.
Some SFTP servers require both an SSH key and password for additional authentication. Anyone who tries to login with the username or password (or both) but doesn't have the correct private/public key match will be denied access to the server, regardless of whether they try to brute-force it.
curl -u <username>: --key ~/.ssh/id_rsa --pubkey ~/.ssh/id_rsa.pub sftp://<remote_host>/<remote_path>
HTTP is unsecured, so any data you send during PUT (e.g. a password or the files you are uploading) could be snooped and read in plain text. Depending on your application, this may or may not be a concern for you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With