PureBasic
PureBasic
FTP over Implicit TLS (Ssl, AuthSsl, AutoFix)
See more FTP Examples
Demonstrates the SSL/TLS connection-mode properties Ssl, AuthSsl, and AutoFix. Setting Ssl true selects implicit FTPS, in which TLS begins immediately after the TCP connection on port 990.
Background: FTP has two ways to add TLS: implicit (this example) starts encrypted from the first byte on a dedicated port, 990; explicit (via
AuthTls) connects in the clear on port 21 and issues AUTH TLS to upgrade. Explicit is the modern standard; implicit persists mainly for legacy servers. AuthSsl is an obsolete AUTH SSL variant to avoid. AutoFix, on by default, infers the mode from the port — disable it when you set these properties explicitly so it does not override your choice.Chilkat PureBasic Downloads
IncludeFile "CkFtp2.pb"
Procedure ChilkatExample()
success.i = 0
ftp.i = CkFtp2::ckCreate()
If ftp.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
CkFtp2::setCkHostname(ftp, "ftp.example.com")
CkFtp2::setCkUsername(ftp, "myFtpLogin")
; 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.
CkFtp2::setCkPassword(ftp, "myPassword")
; Ssl = 1 selects IMPLICIT FTPS: TLS begins immediately after the TCP connection, before
; the greeting. Port 990 is conventional for implicit FTPS. Ssl takes priority over AuthTls
; and AuthSsl.
CkFtp2::setCkSsl(ftp, 1)
CkFtp2::setCkPort(ftp, 990)
; AuthSsl selects the legacy AUTH SSL command and is very uncommon -- use AuthTls (explicit
; FTPS) for modern servers instead. Left 0 here.
CkFtp2::setCkAuthSsl(ftp, 0)
; AutoFix (default 1) automatically adjusts Ssl/AuthTls/AuthSsl based solely on the Port
; (21 or 990). Disable it when setting these properties explicitly, as here.
CkFtp2::setCkAutoFix(ftp, 0)
success = CkFtp2::ckConnect(ftp)
If success = 0
Debug CkFtp2::ckLastErrorText(ftp)
CkFtp2::ckDispose(ftp)
ProcedureReturn
EndIf
Debug "Connected using implicit FTPS."
success = CkFtp2::ckDisconnect(ftp)
If success = 0
Debug CkFtp2::ckLastErrorText(ftp)
CkFtp2::ckDispose(ftp)
ProcedureReturn
EndIf
CkFtp2::ckDispose(ftp)
ProcedureReturn
EndProcedure