# Curl with Private Key

**URL:** <https://clarionhub.com/t/curl-with-private-key/9195>\
**Category:** code\
**Tags:** libcurl, c10\
**Created:** [June 26, 2026, 8:53pm UTC](https://clarionhub.com/t/curl-with-private-key/9195 "2026-06-26T20:53:43Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![John\_Singer](https://clarionhub.com/user_avatar/clarionhub.com/john_singer/32/5717_2.png) [@John\_Singer](https://clarionhub.com/u/John_Singer)\
**Post date:** [June 26, 2026, 8:53pm UTC](https://clarionhub.com/t/curl-with-private-key/9195/1 "2026-06-26T20:53:43Z")

</div>

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.

```clarion
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.

```clarion
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:

```clarion
[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.

---

<div class="post-metadata">

**Author:** ![John\_Singer](https://clarionhub.com/user_avatar/clarionhub.com/john_singer/32/5717_2.png) [@John\_Singer](https://clarionhub.com/u/John_Singer)\
**Post date:** [June 27, 2026, 11:39am UTC](https://clarionhub.com/t/curl-with-private-key/9195/2 "2026-06-27T11:39:41Z")

</div>

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

```clarion
   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')
   

```
