Sample code for 30+ languages & platforms
SQL Server

Send an FTP NOOP (Keep-Alive)

See more FTP Examples

Demonstrates the Chilkat Ftp2.Noop method, which sends the FTP NOOP command. It takes no arguments and succeeds only when the server returns a positive reply.

Background: NOOP asks the server to do nothing and simply reply, which makes it the standard keep-alive: sending one periodically resets the server's idle timer so a long-running job does not lose its control connection between transfers. Because it exercises a real request/reply round trip, a successful NOOP is also firmer evidence the connection is alive than CheckConnection.

Chilkat SQL Server Downloads

SQL Server
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
    DECLARE @hr int
    DECLARE @sTmp0 nvarchar(4000)
    DECLARE @success int
    SELECT @success = 0

    --  Demonstrates the Ftp2.Noop method, which sends the FTP NOOP command.  It takes no arguments.
    --  The server must return a positive reply for the method to succeed.

    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'

    --  Connect and log in (Connect performs both).
    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

    --  NOOP does nothing on the server, but a successful reply confirms the control connection is
    --  still responsive -- useful as a keep-alive during an otherwise idle session.
    EXEC sp_OAMethod @ftp, 'Noop', @success OUT
    IF @success = 0
      BEGIN
        EXEC sp_OAGetProperty @ftp, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @ftp
        RETURN
      END

    PRINT 'NOOP acknowledged by the server.'

    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