C
C
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 C Downloads
#include <C_CkSFtp.h>
void ChilkatSample(void)
{
BOOL success;
HCkSFtp sftp;
int port;
const char *password;
success = FALSE;
// Demonstrates the SFtp.ClearCache method, which clears the internal remote file-attribute cache
// used when the EnableCache property is TRUE. It takes no arguments.
sftp = CkSFtp_Create();
// Connect, authenticate, and initialize the SFTP subsystem.
port = 22;
success = CkSFtp_Connect(sftp,"sftp.example.com",port);
if (success == FALSE) {
printf("%s\n",CkSFtp_lastErrorText(sftp));
CkSFtp_Dispose(sftp);
return;
}
// 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.
password = "mySshPassword";
success = CkSFtp_AuthenticatePw(sftp,"mySshLogin",password);
if (success == FALSE) {
printf("%s\n",CkSFtp_lastErrorText(sftp));
CkSFtp_Dispose(sftp);
return;
}
success = CkSFtp_InitializeSftp(sftp);
if (success == FALSE) {
printf("%s\n",CkSFtp_lastErrorText(sftp));
CkSFtp_Dispose(sftp);
return;
}
// With caching enabled, repeated attribute lookups for the same file are served from memory.
CkSFtp_putEnableCache(sftp,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.
CkSFtp_ClearCache(sftp);
printf("Attribute cache cleared.\n");
CkSFtp_Disconnect(sftp);
CkSFtp_Dispose(sftp);
}