SQL Server
SQL Server
Monitor FTP Transfer Progress
See more FTP Examples
Demonstrates the progress properties CurBytesReceived, CurBytesReceivedStr, CurBytesSent, CurBytesSentStr, ProgressMonSize, PercentDoneScale, and AutoGetSizeForProgress.
Note: The local paths are relative to the application's current working directory. Absolute paths may also be used. Supply the paths appropriate to your own environment.
Background: Percentage progress needs a known total, but FTP does not always report a file's size up front — so
AutoGetSizeForProgress issues a SIZE command before a download, and ProgressMonSize supplies an expected size when even that is unavailable (a one-shot value consumed by the next transfer). PercentDoneScale sets the resolution of progress callbacks. The current byte counts are exposed both as 32-bit integers and as strings, the string forms avoiding integer-width limits for very large transfers.Chilkat SQL Server Downloads
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
DECLARE @hr int
DECLARE @iTmp0 int
DECLARE @sTmp0 nvarchar(4000)
DECLARE @success int
SELECT @success = 0
DECLARE @ftp int
EXEC @hr = sp_OACreate 'Chilkat.Ftp2', @ftp OUT
IF @hr <> 0
BEGIN
PRINT 'Failed to create ActiveX component'
RETURN
END
EXEC sp_OASetProperty @ftp, 'Hostname', 'ftp.example.com'
EXEC sp_OASetProperty @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.
EXEC sp_OASetProperty @ftp, 'Password', 'myPassword'
EXEC sp_OAMethod @ftp, 'Connect', @success OUT
IF @success = 0
BEGIN
EXEC sp_OAGetProperty @ftp, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @ftp
RETURN
END
-- AutoGetSizeForProgress sends a SIZE command before a download so percentage-based progress can
-- be computed.
EXEC sp_OASetProperty @ftp, 'AutoGetSizeForProgress', 1
-- PercentDoneScale sets the value representing one hundred percent in PercentDone callbacks.
-- 1000 gives tenth-of-a-percent resolution.
EXEC sp_OASetProperty @ftp, 'PercentDoneScale', 1000
-- ProgressMonSize is a one-shot expected size for the next download when the size is not
-- otherwise known. It is consumed by the next download and reset to 0.
EXEC sp_OASetProperty @ftp, 'ProgressMonSize', 20485760
EXEC sp_OAMethod @ftp, 'GetFile', @success OUT, 'public_html/bigfile.zip', 'qa_output/bigfile.zip'
IF @success = 0
BEGIN
EXEC sp_OAGetProperty @ftp, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @ftp
RETURN
END
-- After a transfer, the current byte counts are available as 32-bit numbers or as strings (the
-- string forms avoid integer-size limits).
EXEC sp_OAGetProperty @ftp, 'CurBytesReceived', @iTmp0 OUT
PRINT 'Bytes received: ' + @iTmp0
EXEC sp_OAGetProperty @ftp, 'CurBytesReceivedStr', @sTmp0 OUT
PRINT 'Bytes received (str): ' + @sTmp0
EXEC sp_OAGetProperty @ftp, 'CurBytesSent', @iTmp0 OUT
PRINT 'Bytes sent: ' + @iTmp0
EXEC sp_OAGetProperty @ftp, 'CurBytesSentStr', @sTmp0 OUT
PRINT 'Bytes sent (str): ' + @sTmp0
EXEC sp_OAMethod @ftp, 'Disconnect', @success OUT
IF @success = 0
BEGIN
EXEC sp_OAGetProperty @ftp, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @ftp
RETURN
END
EXEC @hr = sp_OADestroy @ftp
END
GO