Sample code for 30+ languages & platforms
DataFlex

Get a Directory Listing as XML

See more FTP Examples

Demonstrates the Chilkat Ftp2.GetXmlDirListing method, which retrieves a directory listing and returns the parsed entries as an XML document rooted at <remoteDir>, with a <file> element per entry. The only argument is the listing pattern; an empty string lists the current directory.

Tip: Code to parse the returned XML can be generated at Chilkat Tools.

Background: This is the parse-friendly listing: Chilkat has already interpreted the server's raw LIST output — whatever its format — into consistent XML with names, sizes, dates, and types as elements. That spares you from writing format-specific parsers and is the right choice when a program, rather than a person, consumes the listing. Load the result into a Chilkat.Xml object to iterate the entries.

Chilkat DataFlex Downloads

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    Handle hoFtp
    String sXml
    String sTemp1
    Boolean bTemp1

    Move False To iSuccess

    //  Demonstrates the Ftp2.GetXmlDirListing method, which returns a directory listing as a parsed
    //  XML document.  The only argument is the listing pattern; an empty string lists the current
    //  remote directory.

    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 = False) Begin
        Get ComLastErrorText Of hoFtp To sTemp1
        Showln sTemp1
        Procedure_Return
    End

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

    //  The XML is rooted at <remoteDir>, with <file> elements for each entry.  This is easier to
    //  parse programmatically than the raw text listing.
    Get ComGetXmlDirListing Of hoFtp "*.html" To sXml
    Get ComLastMethodSuccess Of hoFtp To bTemp1
    If (bTemp1 = False) Begin
        Get ComLastErrorText Of hoFtp To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Showln sXml

    //  The XML can be loaded into a Chilkat.Xml object for further processing.

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



End_Procedure