Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(SQL Server) FTPS with Client Cert from Windows Certificate StoreDemonstrates how to do mutual TLS authentication using a client certificate installed in the Windows certificate store.
-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls. -- CREATE PROCEDURE ChilkatSample AS BEGIN DECLARE @hr int -- Important: Do not use nvarchar(max). See the warning about using nvarchar(max). DECLARE @sTmp0 nvarchar(4000) -- This example requires the Chilkat API to have been previously unlocked. -- See Global Unlock Sample for sample code. DECLARE @ftp int -- Use "Chilkat_9_5_0.Ftp2" for versions of Chilkat < 10.0.0 EXEC @hr = sp_OACreate 'Chilkat.Ftp2', @ftp OUT IF @hr <> 0 BEGIN PRINT 'Failed to create ActiveX component' RETURN END EXEC sp_OASetProperty @ftp, 'Hostname', 'ftp.example.com' -- If using implicit TLS, you probably want port 990.. EXEC sp_OASetProperty @ftp, 'Port', 990 -- Set this to 0 for implicit TLS, otherwise set to 1 for explicit TLS (where port is typically 21). EXEC sp_OASetProperty @ftp, 'AuthTls', 0 -- Set this to 1 for implicit TLS, otherwise set to 0. EXEC sp_OASetProperty @ftp, 'Ssl', 1 DECLARE @cert int -- Use "Chilkat_9_5_0.Cert" for versions of Chilkat < 10.0.0 EXEC @hr = sp_OACreate 'Chilkat.Cert', @cert OUT DECLARE @success int EXEC sp_OAMethod @cert, 'LoadByCommonName', @success OUT, 'The common name of your certificate' IF @success = 0 BEGIN EXEC sp_OAGetProperty @cert, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 EXEC @hr = sp_OADestroy @ftp EXEC @hr = sp_OADestroy @cert RETURN END -- Use this certificate for our TLS mutually authenticated connection: EXEC sp_OAMethod @ftp, 'SetSslClientCert', @success OUT, @cert IF @success = 0 BEGIN EXEC sp_OAGetProperty @cert, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 EXEC @hr = sp_OADestroy @ftp EXEC @hr = sp_OADestroy @cert RETURN END -- Establish the TLS connection with the FTP server. EXEC sp_OAMethod @ftp, 'ConnectOnly', @success OUT IF @success = 0 BEGIN EXEC sp_OAGetProperty @ftp, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 EXEC @hr = sp_OADestroy @ftp EXEC @hr = sp_OADestroy @cert RETURN END -- If a login is required, then login with the FTP account login/password. EXEC sp_OASetProperty @ftp, 'Username', 'myLogin' EXEC sp_OASetProperty @ftp, 'Password', 'myPassword' EXEC sp_OAMethod @ftp, 'LoginAfterConnectOnly', @success OUT IF @success = 0 BEGIN EXEC sp_OAGetProperty @ftp, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 EXEC @hr = sp_OADestroy @ftp EXEC @hr = sp_OADestroy @cert RETURN END -- Do whatever you're doing to do ... -- upload files, download files, etc... -- ..... -- ..... EXEC sp_OAMethod @ftp, 'Disconnect', @success OUT EXEC @hr = sp_OADestroy @ftp EXEC @hr = sp_OADestroy @cert END GO |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.