SQL Server
SQL Server
Pre-Allocate Server Space Before an FTP Upload (ALLO)
See more FTP Examples
Demonstrates the AllocateSize property, which sends the FTP ALLO command to pre-allocate disk space on the server before an upload. Set it to the size in bytes of the file about to be uploaded.
Background:
ALLO asks the server to reserve storage in advance, a requirement of certain legacy systems — older mainframes in particular — that need the exact file size up front to allocate a dataset. Modern servers allocate space dynamically and typically ignore or accept ALLO without needing it, so most applications never set this. Provide it only when targeting a host known to require pre-allocation.Chilkat SQL Server Downloads
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
DECLARE @hr 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
-- AllocateSize sends the FTP ALLO command to pre-allocate disk space on the server before an
-- upload. It is rarely needed -- mainly for certain legacy systems that require the exact size
-- in advance -- since most servers allocate space dynamically. Set it to the size in bytes of
-- the file about to be uploaded.
ERROR: Assignment type mismatch. ExpressionType=int, atgType=uint
EXEC sp_OAMethod @ftp, 'PutFile', @success OUT, 'qa_data/bigfile.zip', 'uploads/bigfile.zip'
IF @success = 0
BEGIN
EXEC sp_OAGetProperty @ftp, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @ftp
RETURN
END
PRINT 'Uploaded with pre-allocation.'
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