PowerBuilder
PowerBuilder
Check FTP Connection and Login Status
See more FTP Examples
Demonstrates the connection-status properties ConnectVerified, LoginVerified, ConnectFailReason, and Greeting.
Background: When
Connect fails, these properties separate the possible causes: ConnectVerified shows whether the TCP connection was established at all, LoginVerified whether authentication then succeeded, and ConnectFailReason gives a numeric code pinpointing the failure — far more actionable than a generic error for distinguishing, say, an unreachable host from a bad password. The Greeting captures the server's opening banner, sometimes useful for identifying the server or its policies.Chilkat PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_Ftp
li_Success = 0
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"
li_Success = loo_Ftp.Connect()
if li_Success <> 1 then
// ConnectFailReason gives a numeric code describing why Connect failed.
Write-Debug "Connect failed, reason code: " + string(loo_Ftp.ConnectFailReason)
Write-Debug loo_Ftp.LastErrorText
destroy loo_Ftp
return
end if
// After a successful connect, these flags report what succeeded.
Write-Debug "TCP connection verified: " + string(loo_Ftp.ConnectVerified)
Write-Debug "Login verified: " + string(loo_Ftp.LoginVerified)
// The Greeting property holds the server's initial greeting banner.
Write-Debug "Server greeting: " + loo_Ftp.Greeting
li_Success = loo_Ftp.Disconnect()
if li_Success = 0 then
Write-Debug loo_Ftp.LastErrorText
destroy loo_Ftp
return
end if
destroy loo_Ftp