Sample code for 30+ languages & platforms
PowerBuilder

Check if the FTP Control Connection is Open

See more FTP Examples

Demonstrates the Chilkat Ftp2.CheckConnection method, which returns whether Chilkat currently considers the FTP control connection to be open. It takes no arguments and does not require the session to be authenticated.

Background: This reports the object's view of the control-connection state, which is distinct from being logged in — it can return true after ConnectOnly and before authentication. For a stronger liveness check that the server is actually responding, send a Noop, which requires a positive reply. FTP servers commonly drop idle control connections after a timeout, so long-lived sessions should verify before assuming the connection is still usable.

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_Ftp

li_Success = 0

//  Demonstrates the Ftp2.CheckConnection method, which returns whether Chilkat currently considers
//  the FTP control connection to be open.  It takes no arguments and does not require the session
//  to be authenticated.

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.Username = "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.
loo_Ftp.Password = "myPassword"

//  Connect and log in (Connect performs both).
li_Success = loo_Ftp.Connect()
if li_Success = 0 then
    Write-Debug loo_Ftp.LastErrorText
    destroy loo_Ftp
    return
end if

//  Check whether the control connection is still open.
if loo_Ftp.CheckConnection() then
    Write-Debug "The control connection is open."
else
    Write-Debug "The control connection is not open."
end if

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



destroy loo_Ftp