Sample code for 30+ languages & platforms
SQL Server

Set the FTP TLS Version and Ciphers

See more FTP Examples

Demonstrates the TLS negotiation properties SslProtocol and SslAllowedCiphers, and reads back the negotiated TlsVersion and TlsCipherSuite after connecting.

Background: SslProtocol sets the allowed (or minimum) TLS version — default lets Chilkat negotiate the best available, while a value like TLS 1.2 or higher enforces a floor for policy compliance. SslAllowedCiphers narrows the offered cipher suites, which most applications should leave at the secure defaults. The read-only TlsVersion and TlsCipherSuite report what was actually agreed, useful for logging and audits.

Chilkat SQL Server Downloads

SQL Server
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
    DECLARE @hr int
    DECLARE @sTmp0 nvarchar(4000)
    DECLARE @success int
    SELECT @success = 0

    DECLARE @ftp int
    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'
    EXEC sp_OASetProperty @ftp, 'Username', 'myFtpLogin'

    EXEC sp_OASetProperty @ftp, 'AuthTls', 1

    --  Normally you would not hard-code the password in source.  You should instead obtain it
    --  from an interactive prompt, environment variable, or a secrets vault.
    EXEC sp_OASetProperty @ftp, 'Password', 'myPassword'

    --  Require at least TLS 1.2.  Accepted values include "default", "TLS 1.3", "TLS 1.2",
    --  "TLS 1.2 or higher", and so on.  "default" lets Chilkat negotiate the best available.
    EXEC sp_OASetProperty @ftp, 'SslProtocol', 'TLS 1.2 or higher'

    --  Optionally restrict the cipher suites offered.  Leave empty to use Chilkat's secure defaults.
    EXEC sp_OASetProperty @ftp, 'SslAllowedCiphers', 'TLS_AES_256_GCM_SHA384,TLS_CHACHA20_POLY1305_SHA256'

    EXEC sp_OAMethod @ftp, 'Connect', @success OUT
    IF @success = 0
      BEGIN
        EXEC sp_OAGetProperty @ftp, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @ftp
        RETURN
      END

    --  After connecting, read back what was actually negotiated.

    EXEC sp_OAGetProperty @ftp, 'TlsVersion', @sTmp0 OUT
    PRINT 'Negotiated TLS version: ' + @sTmp0

    EXEC sp_OAGetProperty @ftp, 'TlsCipherSuite', @sTmp0 OUT
    PRINT 'Negotiated cipher suite: ' + @sTmp0

    EXEC sp_OAMethod @ftp, 'Disconnect', @success OUT
    IF @success = 0
      BEGIN
        EXEC sp_OAGetProperty @ftp, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @ftp
        RETURN
      END

    EXEC @hr = sp_OADestroy @ftp


END
GO