Curl with Private Key

I am trying to upload a file to an sftp site using libcurl. Usually I start these kind of things using the command line curl, which I did and it worked. However in translating it back to Clarion, I have been unable to get it to work.

curl command line - This also works if I remove --pubkey.

curl -v -k sftp://ec2-user@52.27.169.228:22/home/ec2-user/temp/jes.json -T f:\Coins\bin\test.json --key c:\users\john\.ssh\coins.pem --pubkey c:\users\john\.ssh\coins.pem.pub

I used the --libcurl option to get the output for inclusion in a c program and then modified those settings for Clarion libcurl options.

curl        tCurlHttpClass

   CODE
   curl.Init()
   curl.SetSSLVerifyHost(FALSE)
   curl.SetSSLVerifyPeer(FALSE)
   curl.SetDefaultProtocol('sftp')
   curl.UseSSL(CURLUSESSL_ALL)
   curl.SetOpt(CURLOPT_USERAGENT, 'curl/8.21.0')
   curl.SetOpt(CURLOPT_BUFFERSIZE, 102400)
   

   res = curl.SetUserPwd('ec2-user', '') ;  if res then Message('Res = ' & res & ' setUserPwd').
   res = curl.SetOpt(CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2TLS);      if res then Message('Res = ' & res & ' HTTP_VERSION').
   res = curl.SetOpt(CURLOPT_SSH_PRIVATE_KEYFILE, 'c:\users\john\.ssh\coins.pem');   if res then Message('Res = ' & res & ' PRIVATE').
   res = curl.SetOpt(CURLOPT_SSH_PUBLIC_KEYFILE, 'c:\users\john\.ssh\coins.pem.pub');    if res then Message('Res = ' & res & ' PUBLIC').   
   res = curl.SetOpt(CURLOPT_SSLKEY, 'c:\users\john\.ssh\coins.pem');                    if res then Message('Res = ' & res & ' SSLKEY').
   res = curl.SetOpt(CURLOPT_FTP_SKIP_PASV_IP, 1);                       if res then Message('Res = ' & res & ' FTP_SKIP_PASV_IP').
   res = curl.SetOpt(CURLOPT_UPLOAD, 1)
   res = curl.SetOpt(CURLOPT_SSH_AUTH_TYPES, CURLSSH_AUTH_PUBLICKEY)
   
   res = curl.WriteFile('sftp://ec2-user@52.27.169.228:22/home/ec2-user/temp/jes.json', 'f:\coins\bin\test.json')
   if res <> 0 
      Message(curl.StrError(res))
   end

Dbgview shows this on the output:

[libcurl] TEXT: Connected to 52.27.169.228 (52.27.169.228) port 22
[libcurl] TEXT: SSH MD5 public key: NULL
[libcurl] TEXT: SSH SHA256 public key: NULL
[libcurl] TEXT: SSH authentication methods available: publickey,gssapi-keyex,gssapi-with-mic,password
[libcurl] TEXT: Using SSH private key file ''
[libcurl] TEXT: SSH public key authentication failed: Unable to extract public key from private key file: Unable to open private key file
[libcurl] TEXT: Authentication failure

Why does the cli work with the keys but clarion does not?

Any thoughts or suggestions are welcome.

Thank you.

Got it working. The problem was including options that were not necessary. All that was required was:

   curl.Init()
   curl.SetSSLVerifyHost(FALSE)
   curl.SetSSLVerifyPeer(FALSE)
   res = curl.SetOpt(CURLOPT_SSH_AUTH_TYPES, CURLSSH_AUTH_PUBLICKEY)
   res = curl.SetOpt(CURLOPT_SSH_PRIVATE_KEYFILE, LOC:PrivKey)
   ret = curl.SetOpt(CURLOPT_BUFFERSIZE, 102400)
   res = curl.SetOpt(CURLOPT_UPLOAD, 1)
   res = curl.WriteFile('sftp://ec2-user@52.27.169.228:22/home/ec2-user/temp/jes.json', 'f:\coins\bin\test.json')