SQL Server
SQL Server
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 SQL Server Downloads
-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls.
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
DECLARE @hr int
DECLARE @sTmp0 nvarchar(4000)
DECLARE @success int
SELECT @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.
DECLARE @sftp int
EXEC @hr = sp_OACreate 'Chilkat.SFtp', @sftp OUT
IF @hr <> 0
BEGIN
PRINT 'Failed to create ActiveX component'
RETURN
END
-- Connect, authenticate, and initialize the SFTP subsystem.
DECLARE @port int
SELECT @port = 22
EXEC sp_OAMethod @sftp, 'Connect', @success OUT, 'sftp.example.com', @port
IF @success = 0
BEGIN
EXEC sp_OAGetProperty @sftp, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @sftp
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.
DECLARE @password nvarchar(4000)
SELECT @password = 'mySshPassword'
EXEC sp_OAMethod @sftp, 'AuthenticatePw', @success OUT, 'mySshLogin', @password
IF @success = 0
BEGIN
EXEC sp_OAGetProperty @sftp, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @sftp
RETURN
END
EXEC sp_OAMethod @sftp, 'InitializeSftp', @success OUT
IF @success = 0
BEGIN
EXEC sp_OAGetProperty @sftp, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @sftp
RETURN
END
-- With caching enabled, repeated attribute lookups for the same file are served from memory.
EXEC sp_OASetProperty @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.
EXEC sp_OAMethod @sftp, 'ClearCache', NULL
PRINT 'Attribute cache cleared.'
EXEC sp_OAMethod @sftp, 'Disconnect', NULL
EXEC @hr = sp_OADestroy @sftp
END
GO