Chilkat
HOME
Android™
ASP
Visual Basic
VB.NET
C#
iOS (IPhone)
Objective-C
C++
C
MFC
Delphi
FoxPro
Java
Perl
PHP Extension
PHP ActiveX
Python
PowerShell
Ruby
SQL Server
VBScript
SFTP Public-Key AuthenticationDemonstrates how to authenticate with an SSH server using publickey authentication. Downloads: MS Windows Visual C/C++ Libraries Linux/CentOS C/C++ Libraries MAC OS X C/C++ Libraries Solaris C/C++ Libraries C++ Builder Libraries #include <C_CkSFtp.h> #include <C_CkSshKey.h> void ChilkatSample(void) { HCkSFtp sftp; BOOL success; long port; const char * hostname; HCkSshKey key; const char * privKey; // Important: It is helpful to send the contents of the // sftp.LastErrorText property when requesting support. sftp = CkSFtp_Create(); // Any string automatically begins a fully-functional 30-day trial. success = CkSFtp_UnlockComponent(sftp,"Anything for 30-day trial"); if (success != TRUE) { printf("%s\n",CkSFtp_lastErrorText(sftp)); return; } // Set some timeouts, in milliseconds: CkSFtp_putConnectTimeoutMs(sftp,5000); CkSFtp_putIdleTimeoutMs(sftp,15000); // Connect to the SSH server. // The standard SSH port = 22 // The hostname may be a hostname or IP address. hostname = "www.my-ssh-server.com"; port = 22; success = CkSFtp_Connect(sftp,hostname,port); if (success != TRUE) { printf("%s\n",CkSFtp_lastErrorText(sftp)); return; } key = CkSshKey_Create(); // Load a private key from a PEM file: // (Private keys may be loaded from OpenSSH and Putty formats. // Both encrypted and unencrypted private key file formats // are supported. This example loads an unencrypted private // key in OpenSSH format. privKey = CkSshKey_loadText(key,"myPrivateKey.pem"); if (privKey == 0 ) { printf("%s\n",CkSshKey_lastErrorText(key)); return; } success = CkSshKey_FromOpenSshPrivateKey(key,privKey); if (success != TRUE) { printf("%s\n",CkSshKey_lastErrorText(key)); return; } // Authenticate with the SSH server. Chilkat SFTP supports // both password-based authenication as well as public-key // authentication. success = CkSFtp_AuthenticatePk(sftp,"myLogin",key); if (success != TRUE) { printf("%s\n",CkSFtp_lastErrorText(sftp)); return; } printf("%s\n",CkSFtp_lastErrorText(sftp)); printf("Public-Key Authentication Successful!\n"); CkSFtp_Dispose(sftp); CkSshKey_Dispose(key); } |
Need a specific example? Send a request to support@chilkatsoft.com
© 2000-2010 Chilkat Software, Inc. All Rights Reserved.