php - cURL sftp public key authentication fails "Callback Error" -
i have php code works uploading files using curl hosts using user & password ftp, have upload server allows public key auth , getting error: "* ssh public key authentication failed: callback returned error"
i had problem keys not in right format, have since set them in right single line format , stopped "not base64 encoded" errors. can't find much help on callback error online.
my code follows.
$ch = curl_init(); curl_setopt($ch, curlopt_verbose, true); curl_setopt($ch, curlopt_url, 'sftp://user:@12.12.12.12:22/testfile.gz'); curl_setopt($ch, curlopt_protocols, curlproto_sftp); curl_setopt($ch, curlopt_ssh_public_keyfile,'c:\keys\public.pub'); curl_setopt($ch, curlopt_ssh_private_keyfile,'c:\keys\private.ppk'); curl_setopt($ch, curlopt_ssh_host_public_key_md5,'2acfe24108c37a276a93ac3398a5oe8f'); curl_setopt($ch, curlopt_ssh_auth_types,curlssh_auth_publickey); curl_setopt($ch, curlopt_upload, 1); $fp = fopen($localfile, 'r'); curl_setopt($ch, curlopt_infile, $fp); curl_setopt($ch, curlopt_infilesize, filesize($localfile)); $sr = curl_exec ($ch);
here output running test
* connect() 12.12.12.12 port 22 (#0) * trying 12.12.12.12... * connected * connected 12.12.12.12 (12.12.12.12) port 22 (#0) * ssh md5 fingerprint: ebbc61b886c798b25073c912833ffers * ssh authentication methods available: publickey * using ssh public key file c:\keys\public.pub * using ssh private key file c:\keys\private.ppk * ssh public key authentication failed: callback returned error * authentication failure * closing connection #0
any help appreciated
there cases (debian-based distros) when libssh2 built libgcrypt. in those, utilize pem-encoded private key file:
$ openssl rsa -in ~/.ssh/id_rsa -outform pem > id_rsa.pem
php curl ftp sftp scp
No comments:
Post a Comment