Sample code for 30+ languages & platforms
DataFlex

Simple FTP Download

See more FTP Examples

Simple example to download a file from an FTP server.

Chilkat DataFlex Downloads

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    Handle hoFtp
    String sLocalFilename
    String sRemoteFilename
    String sTemp1

    Move False To iSuccess

    // This example requires the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

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

    Set ComHostname Of hoFtp To "ftp.someFtpServer.com"
    Set ComUsername Of hoFtp To "myLogin"
    Set ComPassword Of hoFtp To "myPassword"

    // Connect and login to the FTP server.
    Get ComConnect Of hoFtp To iSuccess
    If (iSuccess <> True) Begin
        Get ComLastErrorText Of hoFtp To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    // Change to the remote directory where the file is located.
    // This step is only necessary if the file is not in the root directory
    // for the FTP account.
    Get ComChangeRemoteDir Of hoFtp "junk" To iSuccess
    If (iSuccess <> True) Begin
        Get ComLastErrorText Of hoFtp To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Move "c:/temp/hamlet.xml" To sLocalFilename
    Move "hamlet.xml" To sRemoteFilename

    // Download a file.
    Get ComGetFile Of hoFtp sRemoteFilename sLocalFilename To iSuccess
    If (iSuccess <> True) Begin
        Get ComLastErrorText Of hoFtp To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get ComDisconnect Of hoFtp To iSuccess

    Showln "File Downloaded!"


End_Procedure