SQL Server
SQL Server
Connect Through a Traditional FTP Proxy
See more FTP Examples
Demonstrates connecting through a traditional FTP application proxy or firewall using ProxyHostname, ProxyPort, ProxyUsername, ProxyPassword, and ProxyMethod.
Background: A traditional FTP proxy speaks FTP and relays your login to the real server using one of several site-specific handshake sequences — which is why
ProxyMethod exists: it selects the exact USER/PASS/SITE order the proxy expects (0 means no FTP proxy). The proxy's own credentials are separate from the FTP server login. Choose the ProxyMethod value that matches your firewall's documented behavior.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'
-- The FTP proxy/firewall to connect through.
EXEC sp_OASetProperty @ftp, 'ProxyHostname', 'ftp-proxy.example.com'
EXEC sp_OASetProperty @ftp, 'ProxyPort', 21
-- The proxy's own credentials (distinct from the FTP server login).
EXEC sp_OASetProperty @ftp, 'ProxyUsername', 'myProxyLogin'
EXEC sp_OASetProperty @ftp, 'ProxyPassword', 'myProxyPassword'
-- ProxyMethod selects the login sequence the proxy expects. 0 (default) means no FTP proxy;
-- values 1 and up select specific USER/PASS/SITE sequences documented for the property.
EXEC sp_OASetProperty @ftp, 'ProxyMethod', 1
-- 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
PRINT 'Connected through the FTP proxy.'
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