Programming Examples

ChilkatHOMEAndroid™ASPVisual BasicVB.NETC#iOS (IPhone)Objective-CC++CMFCDelphiFoxProJavaPerl
PHP ExtensionPHP ActiveXPythonPowerShellRubySQL ServerVBScript

C Examples

Bounced Mail
Bz2
Certificates/Keys
Charset
CSV
DKIM / DomainKey
Diffie-Hellman
DSA
Email Object
Encryption
FileAccess
FTP
HTML Conversion
HTTP
IMAP
MHT / HTML Email
MIME
NTLM
POP3
RSA
SMTP
Socket
Spider
SSH Key
SSH
SSH Tunnel
SFTP
Tar
Upload
XML
Zip
Amazon S3

 

 

 

 

 

 

 

 

Secure FTP with .crt and .pvk (private key file)

(The LoadPvkFile method used in this example is only available in Chilkat builds for the Windows operating system.)

Chilkat FTP2 provides the ability to use a client certificate with secure FTP (implicit or explicit SSL/TLS). This example demonstrates how to load a certificate from separate .crt (or .cer) and .pvk files and use it as the client-side SSL cert. The .pvk contains the private key. The .crt/.cer file contains the PEM or DER encoded digital certificate. Note: Client-side certificates are only needed in situations where the server demands one.

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_CkFtp2.h>
#include <C_CkCert.h>
#include <C_CkPrivateKey.h>

void ChilkatSample(void)
    {
    HCkFtp2 ftp;
    BOOL success;
    HCkCert cert;
    const char * password;
    HCkPrivateKey pvk;

    ftp = CkFtp2_Create();

    //  Any string unlocks the component for the 1st 30-days.
    success = CkFtp2_UnlockComponent(ftp,"Anything for 30-day trial");
    if (success != TRUE) {
        printf("%s\n",CkFtp2_lastErrorText(ftp));
        return;
    }

    CkFtp2_putHostname(ftp,"ftp.***.com");
    CkFtp2_putPort(ftp,21);
    CkFtp2_putUsername(ftp,"testLogin");
    CkFtp2_putPassword(ftp,"testPassword");

    //  This example will use explict TLS/SSL.
    //  Establish an explicit secure channel after connection
    //  on the standard FTP port 21.
    CkFtp2_putAuthTls(ftp,TRUE);

    //  The Ssl property is for establishing an implicit SSL connection
    //  on port 990.  Because this example uses explicit SSL, it
    //  should remain FALSE.
    CkFtp2_putSsl(ftp,FALSE);

    cert = CkCert_Create();

    //  LoadFromFile will load either PEM and DER formatted files.
    //  It automatically recognizes the file format based on the
    //  file contents.
    success = CkCert_LoadFromFile(cert,"Test.crt");
    if (success != TRUE) {
        printf("%s\n",CkCert_lastErrorText(cert));
        return;
    }

    password = "test";
    pvk = CkPrivateKey_Create();
    success = CkPrivateKey_LoadPvkFile(pvk,"Test.pvk",password);
    if (success != TRUE) {
        printf("%s\n",CkPrivateKey_lastErrorText(pvk));
        return;
    }

    success = CkCert_SetPrivateKey(cert,pvk);
    if (success != TRUE) {
        printf("%s\n",CkCert_lastErrorText(cert));
        return;
    }

    //  Use this certificate for our secure (SSL/TLS) connection:
    CkFtp2_SetSslClientCert(ftp,cert);

    //  Connect and login to the FTP server.  The connection is
    //  made secure because of the AuthTls setting.
    success = CkFtp2_Connect(ftp);
    if (success != TRUE) {
        printf("%s\n",CkFtp2_lastErrorText(ftp));
        return;
    }
    else {
        //  LastErrorText contains information even when
        //  successful. This allows you to visually verify
        //  that the secure connection actually occurred.
        printf("%s\n",CkFtp2_lastErrorText(ftp));
    }

    printf("Secure FTP Channel Established!\n");

    //  Do whatever you're doing to do ...
    //  upload files, download files, etc...

    CkFtp2_Disconnect(ftp);

    CkFtp2_Dispose(ftp);
    CkCert_Dispose(cert);
    CkPrivateKey_Dispose(pvk);

    }

Need a specific example? Send a request to support@chilkatsoft.com

© 2000-2010 Chilkat Software, Inc. All Rights Reserved.