SQL Server Stored Procedure Examples

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

SQL Server
Stored Procedure Examples

Quick Start
Encryption
File Access
IMAP
POP3
SMTP
Email Object
DKIM / DomainKey
FTP
HTML Conversion
HTTP
MHT
MIME
NTLM
RSA
Diffie-Hellman
DSA
Socket
Spider
SSH Key
SSH
SSH Tunnel
SFTP
String
Tar
Upload
XML
XMP
Zip

Amazon S3
Bz2
CSV
FileAccess
Byte Array
RSS
Atom
Self-Extractor

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.

Download 32-bit Chilkat FTP2 ActiveX (.msi)

Download All 32-bit Chilkat ActiveX Components (.zip)

Download All 64-bit Chilkat ActiveX Components (.zip)

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.