DataFlex
DataFlex
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 DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Handle hoSftp
Integer iPort
String sPassword
String sTemp1
Move False To iSuccess
// Demonstrates the SFtp.ClearCache method, which clears the internal remote file-attribute cache
// used when the EnableCache property is True. It takes no arguments.
Get Create (RefClass(cComChilkatSFtp)) To hoSftp
If (Not(IsComObjectCreated(hoSftp))) Begin
Send CreateComObject of hoSftp
End
// Connect, authenticate, and initialize the SFTP subsystem.
Move 22 To iPort
Get ComConnect Of hoSftp "sftp.example.com" iPort To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoSftp To sTemp1
Showln sTemp1
Procedure_Return
End
// 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.
Move "mySshPassword" To sPassword
Get ComAuthenticatePw Of hoSftp "mySshLogin" sPassword To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoSftp To sTemp1
Showln sTemp1
Procedure_Return
End
Get ComInitializeSftp Of hoSftp To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoSftp To sTemp1
Showln sTemp1
Procedure_Return
End
// With caching enabled, repeated attribute lookups for the same file are served from memory.
Set ComEnableCache Of hoSftp To True
// ... 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.
Send ComClearCache To hoSftp
Showln "Attribute cache cleared."
Send ComDisconnect To hoSftp
End_Procedure