ComponentPro UltimateFtp

      KeepAliveAsync() Method

      See AlsoMembers Options: Show AllLanguage Filter: AllSend comments on this topic to ComponentPro
      Begins an asynchronous operation to send a command or data packet to the server to keep the connection alive.

      Syntax

      public ExtendedAsyncResult KeepAliveAsync()

      Return Value

      An object that references the asynchronous operation.

      Examples

      Shows how to use KeepAliveAsync method to keep the connection alive (Task-based approach).

      using System;
      using System.ComponentModel;
      using ComponentPro.IO;
      using ComponentPro.Net;
      using ComponentPro;
      
      ...
      
      async static void Main2()
      {
          // Create a new class instance. 
          Ftp client = new Ftp();
      
          // Connect to the FTP server. 
          client.Connect("myserver");
      
          // Authenticate. 
          client.Authenticate("userName", "password");
      
          // ... 
       
          // The event KeepAliveCompleted is fired when the operation completes. 
          client.KeepAliveCompleted += callback2;
      
          // Keep the connection alive. 
          await client.KeepAliveAsync("user state");
      
          // ... 
       
          // Disconnect. 
          client.Disconnect();
      }
      
      private static void callback2(object sender, AsyncCompletedEventArgs e)
      {
          if (e.Error != null)
              Console.WriteLine("Error: " + e.Error.ToString());
      
          Console.WriteLine("Method completed. User state: " + e.UserState);
      }

      Shows how to use the KeepAliveAsync method to keep the connection alive (Event-based approach).

      using System;
      using System.ComponentModel;
      using ComponentPro.IO;
      using ComponentPro.Net;
      using ComponentPro;
      
      ...
      
      static void Main()
      {
          // Create a new class instance. 
          Ftp client = new Ftp();
      
          // The KeepAliveCompleted event is fired when the operation completes. 
          client.KeepAliveCompleted += client_KeepAliveCompleted;
      
          // Connect to the FTP server. 
          client.Connect("myserver");
      
          // Authenticate. 
          client.Authenticate("userName", "password");
      
          // ... 
       
          // Send NOOP command to the server. 
          client.KeepAliveAsync();
      
          // ... 
       
          // Disconnect. 
          client.Disconnect();
      }
      
      static void client_KeepAliveCompleted(object sender, AsyncCompletedEventArgs e)
      {
          // Ftp client = (Ftp)sender; 
          if (e.Error != null)
              Console.WriteLine("Error: " + e.Error.Message);
      
          Console.WriteLine("Method completed. User-state: " + e.UserState);
      }

      Framework

      .NET Compact Framework.NET Compact Framework

      Supported version: 2.0, 3.5, and 3.9
      Assembly: ComponentPro.Ftp.CF (in ComponentPro.Ftp.CF.dll)

      .NET Framework.NET Framework

      Supported version: 2.0, 3.0, 3.5, 4.0, 4.5.x, 4.6.x and later
      Assembly: ComponentPro.Ftp (in ComponentPro.Ftp.dll)

      See Also