Sample code for 30+ languages & platforms
PowerBuilder

Upgrade an FTP Control Channel to TLS (ConvertToTls)

See more FTP Examples

Demonstrates the Chilkat Ftp2.ConvertToTls method, which upgrades an already-connected clear FTP control channel to explicit TLS. It takes no arguments and is used with a manually staged connection created by ConnectOnly while Ssl is disabled.

Background: This exposes the explicit-FTPS AUTH TLS upgrade as a discrete step for the rare case where you need to do something on the clear connection first — inspect the greeting, apply a workaround — before securing it. In the normal case you simply set AuthTls and let Connect perform the upgrade automatically; this manual path exists for staged control.

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_Ftp

li_Success = 0

//  Demonstrates the Ftp2.ConvertToTls method, which upgrades an already-connected clear FTP control
//  channel to explicit TLS.  It takes no arguments.  It is used with a manually staged connection
//  created by ConnectOnly while Ssl is disabled.

loo_Ftp = create oleobject
li_rc = loo_Ftp.ConnectToNewObject("Chilkat.Ftp2")
if li_rc < 0 then
    destroy loo_Ftp
    MessageBox("Error","Connecting to COM object failed")
    return
end if

loo_Ftp.Hostname = "ftp.example.com"
loo_Ftp.Port = 21

//  Connect in clear text first (Ssl is false).
li_Success = loo_Ftp.ConnectOnly()
if li_Success = 0 then
    Write-Debug loo_Ftp.LastErrorText
    destroy loo_Ftp
    return
end if

//  Upgrade the control channel to explicit TLS (AUTH TLS).
li_Success = loo_Ftp.ConvertToTls()
if li_Success = 0 then
    Write-Debug loo_Ftp.LastErrorText
    destroy loo_Ftp
    return
end if

//  Now authenticate over the encrypted control channel.
loo_Ftp.Username = "myFtpLogin"
loo_Ftp.Password = "myPassword"
li_Success = loo_Ftp.LoginAfterConnectOnly()
if li_Success = 0 then
    Write-Debug loo_Ftp.LastErrorText
    destroy loo_Ftp
    return
end if

Write-Debug "Control channel upgraded to TLS and logged in."

li_Success = loo_Ftp.Disconnect()
if li_Success = 0 then
    Write-Debug loo_Ftp.LastErrorText
    destroy loo_Ftp
    return
end if



destroy loo_Ftp