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
|
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.
CREATE PROCEDURE ChilkatSample AS BEGIN DECLARE @hr int DECLARE @sTmp0 nvarchar(4000) DECLARE @ftp int EXEC @hr = sp_OACreate 'Chilkat.Ftp2', @ftp OUT IF @hr <> 0 BEGIN PRINT 'Failed to create ActiveX component' RETURN END DECLARE @success int -- Any string unlocks the component for the 1st 30-days. EXEC sp_OAMethod @ftp, 'UnlockComponent', @success OUT, 'Anything for 30-day trial' IF @success <> 1 BEGIN EXEC sp_OAGetProperty @ftp, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 RETURN END EXEC sp_OASetProperty @ftp, 'Hostname', 'ftp.***.com' EXEC sp_OASetProperty @ftp, 'Port', 21 EXEC sp_OASetProperty @ftp, 'Username', 'testLogin' EXEC sp_OASetProperty @ftp, 'Password', 'testPassword' -- This example will use explict TLS/SSL. -- Establish an explicit secure channel after connection -- on the standard FTP port 21. EXEC sp_OASetProperty @ftp, 'AuthTls', 1 -- The Ssl property is for establishing an implicit SSL connection -- on port 990. Because this example uses explicit SSL, it -- should remain 0. EXEC sp_OASetProperty @ftp, 'Ssl', 0 DECLARE @cert int EXEC @hr = sp_OACreate 'Chilkat.Cert', @cert OUT IF @hr <> 0 BEGIN PRINT 'Failed to create ActiveX component' RETURN END -- LoadFromFile will load either PEM and DER formatted files. -- It automatically recognizes the file format based on the -- file contents. EXEC sp_OAMethod @cert, 'LoadFromFile', @success OUT, 'Test.crt' IF @success <> 1 BEGIN EXEC sp_OAGetProperty @cert, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 RETURN END DECLARE @password nvarchar(4000) SELECT @password = 'test' DECLARE @pvk int EXEC @hr = sp_OACreate 'Chilkat.PrivateKey', @pvk OUT IF @hr <> 0 BEGIN PRINT 'Failed to create ActiveX component' RETURN END EXEC sp_OAMethod @pvk, 'LoadPvkFile', @success OUT, 'Test.pvk', @password IF @success <> 1 BEGIN EXEC sp_OAGetProperty @pvk, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 RETURN END EXEC sp_OAMethod @cert, 'SetPrivateKey', @success OUT, @pvk IF @success <> 1 BEGIN EXEC sp_OAGetProperty @cert, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 RETURN END -- Use this certificate for our secure (SSL/TLS) connection: EXEC sp_OAMethod @ftp, 'SetSslClientCert', NULL, @cert -- Connect and login to the FTP server. The connection is -- made secure because of the AuthTls setting. EXEC sp_OAMethod @ftp, 'Connect', @success OUT IF @success <> 1 BEGIN EXEC sp_OAGetProperty @ftp, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 RETURN END ELSE BEGIN -- LastErrorText contains information even when -- successful. This allows you to visually verify -- that the secure connection actually occurred. EXEC sp_OAGetProperty @ftp, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 END PRINT 'Secure FTP Channel Established!' -- Do whatever you're doing to do ... -- upload files, download files, etc... EXEC sp_OAMethod @ftp, 'Disconnect', NULL END GO |
© 2000-2010 Chilkat Software, Inc. All Rights Reserved.