![]() |
Chilkat • HOME • Android™ • AutoIt • C • C# • C++ • Chilkat2-Python • CkPython • Classic ASP • DataFlex • Delphi DLL • Go • Java • Node.js • Objective-C • PHP Extension • Perl • PowerBuilder • PowerShell • PureBasic • Ruby • SQL Server • Swift • Tcl • Unicode C • Unicode C++ • VB.NET • VBScript • Visual Basic 6.0 • Visual FoxPro • Xojo Plugin
(PureBasic) FTPS with Client Cert from Windows Certificate StoreDemonstrates how to do mutual TLS authentication using a client certificate installed in the Windows certificate store.
IncludeFile "CkFtp2.pb" IncludeFile "CkCert.pb" Procedure ChilkatExample() ; This example requires the Chilkat API to have been previously unlocked. ; See Global Unlock Sample for sample code. ftp.i = CkFtp2::ckCreate() If ftp.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkFtp2::setCkHostname(ftp, "ftp.example.com") ; If using implicit TLS, you probably want port 990.. CkFtp2::setCkPort(ftp, 990) ; Set this to 0 for implicit TLS, otherwise set to 1 for explicit TLS (where port is typically 21). CkFtp2::setCkAuthTls(ftp, 0) ; Set this to 1 for implicit TLS, otherwise set to 0. CkFtp2::setCkSsl(ftp, 1) cert.i = CkCert::ckCreate() If cert.i = 0 Debug "Failed to create object." ProcedureReturn EndIf success.i = CkCert::ckLoadByCommonName(cert,"The common name of your certificate") If success = 0 Debug CkCert::ckLastErrorText(cert) CkFtp2::ckDispose(ftp) CkCert::ckDispose(cert) ProcedureReturn EndIf ; Use this certificate for our TLS mutually authenticated connection: success = CkFtp2::ckSetSslClientCert(ftp,cert) If success = 0 Debug CkCert::ckLastErrorText(cert) CkFtp2::ckDispose(ftp) CkCert::ckDispose(cert) ProcedureReturn EndIf ; Establish the TLS connection with the FTP server. success = CkFtp2::ckConnectOnly(ftp) If success = 0 Debug CkFtp2::ckLastErrorText(ftp) CkFtp2::ckDispose(ftp) CkCert::ckDispose(cert) ProcedureReturn EndIf ; If a login is required, then login with the FTP account login/password. CkFtp2::setCkUsername(ftp, "myLogin") CkFtp2::setCkPassword(ftp, "myPassword") success = CkFtp2::ckLoginAfterConnectOnly(ftp) If success = 0 Debug CkFtp2::ckLastErrorText(ftp) CkFtp2::ckDispose(ftp) CkCert::ckDispose(cert) ProcedureReturn EndIf ; Do whatever you're doing to do ... ; upload files, download files, etc... ; ..... ; ..... success = CkFtp2::ckDisconnect(ftp) CkFtp2::ckDispose(ftp) CkCert::ckDispose(cert) ProcedureReturn EndProcedure |
© 2000-2025 Chilkat Software, Inc. All Rights Reserved.