Sample code for 30+ languages & platforms
Visual FoxPro

Authenticate an SSH Tunnel with a Private Key

See more Socket/SSL/TLS Examples

Demonstrates Socket.SshAuthenticatePk, which authenticates an SSH tunnel session using a private key loaded into an SshKey object. Call SshOpenTunnel first.

The file path is relative to the application's current working directory. An absolute path may also be used. Supply the path appropriate to your own environment.

Background. The SSH server must have the corresponding public key authorized for the account. If the private key is encrypted, set the SshKey.Password property before loading it.

Chilkat Visual FoxPro Downloads

Visual FoxPro
LOCAL lnSuccess
LOCAL loSocket
LOCAL loSshKey
LOCAL lcKeyText

lnSuccess = 0

loSocket = CreateObject('Chilkat.Socket')

lnSuccess = loSocket.SshOpenTunnel("ssh.example.com",22)
IF (lnSuccess = 0) THEN
    ? loSocket.LastErrorText
    RELEASE loSocket
    CANCEL
ENDIF

*  Load the SSH private key.  The file path is relative to the application's current working
*  directory.  If the key is encrypted, set the SshKey.Password property before calling
*  FromOpenSshPrivateKey.
loSshKey = CreateObject('Chilkat.SshKey')
lcKeyText = loSshKey.LoadText("qa_data/id_ed25519")
IF (loSshKey.LastMethodSuccess = 0) THEN
    ? loSshKey.LastErrorText
    RELEASE loSocket
    RELEASE loSshKey
    CANCEL
ENDIF

lnSuccess = loSshKey.FromOpenSshPrivateKey(lcKeyText)
IF (lnSuccess = 0) THEN
    ? loSshKey.LastErrorText
    RELEASE loSocket
    RELEASE loSshKey
    CANCEL
ENDIF

*  Authenticate the SSH tunnel session using public-key authentication.  The SSH server must have the
*  corresponding public key authorized for the account.
lnSuccess = loSocket.SshAuthenticatePk("sshUser",loSshKey)
IF (lnSuccess = 0) THEN
    ? loSocket.LastErrorText
    RELEASE loSocket
    RELEASE loSshKey
    CANCEL
ENDIF

? "SSH public-key authentication succeeded."

RELEASE loSocket
RELEASE loSshKey