Sample code for 30+ languages & platforms
DataFlex

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 DataFlex Downloads

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    Handle hoFtp
    String sTemp1
    Integer iTemp1
    Boolean bTemp1

    Move False To iSuccess

    Get Create (RefClass(cComChilkatFtp2)) To hoFtp
    If (Not(IsComObjectCreated(hoFtp))) Begin
        Send CreateComObject of hoFtp
    End

    Set ComHostname Of hoFtp To "ftp.example.com"
    Set ComUsername Of hoFtp To "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.
    Set ComPassword Of hoFtp To "myPassword"

    Get ComConnect Of hoFtp To iSuccess
    If (iSuccess <> True) Begin
        //  ConnectFailReason gives a numeric code describing why Connect failed.
        Get ComConnectFailReason Of hoFtp To iTemp1
        Showln "Connect failed, reason code: " iTemp1
        Get ComLastErrorText Of hoFtp To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    //  After a successful connect, these flags report what succeeded.
    Get ComConnectVerified Of hoFtp To bTemp1
    Showln "TCP connection verified: " bTemp1
    Get ComLoginVerified Of hoFtp To bTemp1
    Showln "Login verified: " bTemp1

    //  The Greeting property holds the server's initial greeting banner.
    Get ComGreeting Of hoFtp To sTemp1
    Showln "Server greeting: " sTemp1

    Get ComDisconnect Of hoFtp To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoFtp To sTemp1
        Showln sTemp1
        Procedure_Return
    End



End_Procedure