Sample code for 30+ languages & platforms
DataFlex

Clear the FTP Directory Listing Cache

See more FTP Examples

Demonstrates the Chilkat Ftp2.ClearDirCache method, which clears the cached listing for the current remote directory. It takes no arguments; the next indexed-listing call fetches a fresh listing from the server.

Background: The index-based directory API caches the listing the first time you read it, so repeated accessor calls avoid extra round trips. The trade-off is staleness: if the directory changes — files added or removed, whether by your own operations or another process — the cache still reflects the old state. ClearDirCache discards it so the next GetDirCount queries the server again.

Chilkat DataFlex Downloads

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    Handle hoFtp
    Integer n
    String sTemp1

    Move False To iSuccess

    //  Demonstrates the Ftp2.ClearDirCache method, which clears the cached listing for the current
    //  remote directory.  It takes no arguments and is a void method.

    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 first GetDirCount caches the listing.
    Get ComGetDirCount Of hoFtp To n
    Showln "Entries: " n

    //  ... the remote directory changes (files added or removed by another process) ...

    //  Discard the cache so the next listing call fetches fresh data from the server.
    Send ComClearDirCache To hoFtp

    Get ComGetDirCount Of hoFtp To n
    Showln "Entries after refresh: " n

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



End_Procedure