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
Verify FTP SSL Server CertificateThis example demonstrates how to verify the FTP server's certificate and authenticity. The intent is to verify the authenticity of the server before passing a login/password to it. 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 FreeBSD C++ Libraries HP-UX C++ Libraries BlackBerry QNX C++ Libraries #include <C_CkFtp2.h> #include <C_CkCert.h> void ChilkatSample(void) { HCkFtp2 ftp; BOOL success; HCkCert cert; 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.myftpserver.com"); CkFtp2_putUsername(ftp,"myUsername"); CkFtp2_putPassword(ftp,"myPassword"); // Establish an AUTH SSL secure channel after connection // on the standard FTP port 21. CkFtp2_putAuthSsl(ftp,TRUE); // The Ssl property is for establishing an implicit SSL connection // on port 990. Do not set it. CkFtp2_putSsl(ftp,FALSE); // Indicate that the FTP server must have a verifiable SSL certificate. // Do not accept self-signed certs or certificates that are // expired, revoked, or cannot be verified to a root authority: CkFtp2_putRequireSslCertVerify(ftp,TRUE); // You may also set a requirement. In this example, // the certificate's Common Name (CN) must match the // required string exactly: CkFtp2_SetSslCertRequirement(ftp,"subjectcn","Chilkat Software, Inc."); // Connect and login to the FTP server. 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)); } // After logging on, you may examine the FTP server's cert: cert = CkFtp2_GetSslServerCert(ftp); if (cert == 0 ) { printf("No server certificate!\n"); } else { // Display the distinguished name of the SSL cert. printf("%s\n",CkCert_subjectDN(cert)); } printf("Secure FTP Channel Established!\n"); // Do whatever you're doing to do ... // upload files, download files, etc... CkFtp2_Disconnect(ftp); CkFtp2_Dispose(ftp); } |
Need a specific example? Send a request to support@chilkatsoft.com
© 2000-2010 Chilkat Software, Inc. All Rights Reserved.