Sample code for 30+ languages & platforms
Xbase++

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 Xbase++ Downloads

Xbase++
LOCAL nSuccess
LOCAL oFtp

nSuccess := 0

oFtp := CreateObject("Chilkat.Ftp2")

oFtp:Hostname := "ftp.example.com"
oFtp: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.
oFtp:Password := "myPassword"

nSuccess := oFtp:Connect()
IF (nSuccess != 1)
    //  ConnectFailReason gives a numeric code describing why Connect failed.
    ? "Connect failed, reason code: " + Str(oFtp:ConnectFailReason)
    ? oFtp:LastErrorText
    oFtp:destroy()
    RETURN
ENDIF

//  After a successful connect, these flags report what succeeded.
? "TCP connection verified: " + Str(oFtp:ConnectVerified)
? "Login verified: " + Str(oFtp:LoginVerified)

//  The Greeting property holds the server's initial greeting banner.
? "Server greeting: " + oFtp:Greeting

nSuccess := oFtp:Disconnect()
IF (nSuccess == 0)
    ? oFtp:LastErrorText
    oFtp:destroy()
    RETURN
ENDIF

oFtp:destroy()