PowerBuilder
PowerBuilder
Clear the SFTP File-Attribute Cache
See more SFTP Examples
Demonstrates the Chilkat SFtp.ClearCache method, which clears the internal remote file-attribute cache used when the EnableCache property is enabled. It takes no arguments.
Background: When caching is on, Chilkat remembers file attributes it has already fetched so that repeated lookups — common when listing then stat-ing many files — avoid extra round trips. The trade-off is staleness: if files change on the server, the cache can report old sizes or timestamps.
ClearCache discards those remembered values so the next lookup queries the server fresh, which you would do after a known change or before a check that must be current.Chilkat PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_Sftp
integer li_Port
string ls_Password
li_Success = 0
// Demonstrates the SFtp.ClearCache method, which clears the internal remote file-attribute cache
// used when the EnableCache property is 1. It takes no arguments.
loo_Sftp = create oleobject
li_rc = loo_Sftp.ConnectToNewObject("Chilkat.SFtp")
if li_rc < 0 then
destroy loo_Sftp
MessageBox("Error","Connecting to COM object failed")
return
end if
// Connect, authenticate, and initialize the SFTP subsystem.
li_Port = 22
li_Success = loo_Sftp.Connect("sftp.example.com",li_Port)
if li_Success = 0 then
Write-Debug loo_Sftp.LastErrorText
destroy loo_Sftp
return
end if
// 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.
ls_Password = "mySshPassword"
li_Success = loo_Sftp.AuthenticatePw("mySshLogin",ls_Password)
if li_Success = 0 then
Write-Debug loo_Sftp.LastErrorText
destroy loo_Sftp
return
end if
li_Success = loo_Sftp.InitializeSftp()
if li_Success = 0 then
Write-Debug loo_Sftp.LastErrorText
destroy loo_Sftp
return
end if
// With caching enabled, repeated attribute lookups for the same file are served from memory.
loo_Sftp.EnableCache = 1
// ... perform operations that populate the cache ...
// Clear the cache so that subsequent attribute lookups query the server again, for example
// after files on the server are known to have changed.
loo_Sftp.ClearCache()
Write-Debug "Attribute cache cleared."
loo_Sftp.Disconnect()
destroy loo_Sftp