Sample code for 30+ languages & platforms
PowerBuilder

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

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_Ftp
integer n

li_Success = 0

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

loo_Ftp = create oleobject
li_rc = loo_Ftp.ConnectToNewObject("Chilkat.Ftp2")
if li_rc < 0 then
    destroy loo_Ftp
    MessageBox("Error","Connecting to COM object failed")
    return
end if

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

li_Success = loo_Ftp.Connect()
if li_Success = 0 then
    Write-Debug loo_Ftp.LastErrorText
    destroy loo_Ftp
    return
end if

li_Success = loo_Ftp.ChangeRemoteDir("public_html")
if li_Success = 0 then
    Write-Debug loo_Ftp.LastErrorText
    destroy loo_Ftp
    return
end if

//  The first GetDirCount caches the listing.
n = loo_Ftp.GetDirCount()
Write-Debug "Entries: " + string(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.
loo_Ftp.ClearDirCache()

n = loo_Ftp.GetDirCount()
Write-Debug "Entries after refresh: " + string(n)

li_Success = loo_Ftp.Disconnect()
if li_Success = 0 then
    Write-Debug loo_Ftp.LastErrorText
    destroy loo_Ftp
    return
end if



destroy loo_Ftp