ComponentPro UltimateFtp

      GetUploadStreamCompleted Event

      See AlsoMembers Options: Show AllLanguage Filter: AllSend comments on this topic to ComponentPro
      Occurs when an asynchronous GetUploadStreamAsync operation completes.

      Syntax

      public event ExtendedAsyncCompletedEventHandler<TResult> GetUploadStreamCompleted

      Examples

      Shows how to use GetUploadStreamAsync method to asynchronously decompress a file and upload to the server (Task-based approach).

      using System;
      using System.IO;
      using ComponentPro;
      using ComponentPro.Compression;
      using ComponentPro.Net;
      
      ...
      
      async static void Main2()
      {
          // Create a new class instance. 
          Ftp client = new Ftp();
      
          // Connect to the FTP server. 
          client.Connect("localhost");
      
          // Authenticate. 
          client.Authenticate("test", "test");
      
          // ... 
       
          // The GetUploadStreamCompleted event is fired when the operation completes. 
          client.GetUploadStreamCompleted += callback2;
          // Get upload stream for remote file 'compressed.z'. 
          Stream ostream = await client.GetUploadStreamAsync("/file.dat", SeekOrigin.Begin, 0, "user state");
      
          // ... 
       
          // Create new file 
          FileStream fi = new FileStream("c:\\file.dat", FileMode.Open);
      
          byte[] buf = new byte[8192];
          int read;
          while ((read = fi.Read(buf, 0, 8192)) > 0) // Read from the Zlib stream. 
          {
              ostream.Write(buf, 0, read); // And write to the upload stream. 
          }
      
          fi.Close();
          ostream.Close();
      
          // ... 
       
          // Disconnect. 
          client.Disconnect();
      }
      
      private static void callback2(object sender, ExtendedAsyncCompletedEventArgs<Stream> e)
      {
          if (e.Error != null)
              Console.WriteLine("Error: " + e.Error.ToString());
          Console.WriteLine("Method completed. User state: " + e.UserState);
      }

      Shows how to use GetUploadStreamAsync method to asynchronously decompress a file and upload to the server (Event-based approach).

      using System;
      using System.IO;
      using ComponentPro;
      using ComponentPro.Compression;
      using ComponentPro.Net;
      
      ...
      
      static void Main()
      {
          // Create a new class instance. 
          Ftp client = new Ftp();
      
          // Connect to the FTP server. 
          client.Connect("localhost");
      
          // Authenticate. 
          client.Authenticate("test", "test");
      
          // ... 
       
          // The GetUploadStreamCompleted event is fired when the operation completes. 
          client.GetUploadStreamCompleted += client_GetUploadStreamCompleted;
          // Get upload stream for remote file 'compressed.z'. 
          client.GetUploadStreamAsync("/file.dat", SeekOrigin.Begin, 0);
      
          // Wait until it's completed. 
       
          // ... 
       
          // Disconnect. 
          client.Disconnect();
      }
      
      static void client_GetUploadStreamCompleted(object sender, ExtendedAsyncCompletedEventArgs<Stream> e)
      {
          Ftp client = (Ftp) sender;
      
          if (e.Error != null)
              Console.WriteLine("Error: " + e.Error.ToString());
          else 
          {
              Stream ostream = e.Result;
      
              // Create new file 
              FileStream fi = new FileStream("c:\\file.dat", FileMode.Open);
              
              byte[] buf = new byte[8192];
              int read;
              while ((read = fi.Read(buf, 0, 8192)) > 0) // Read from the Zlib stream. 
              {
                  ostream.Write(buf, 0, read); // And write to the upload stream. 
              }
              
              fi.Close();
              ostream.Close();
          }
      }

      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)

      Xamarin AndroidXamarin Android

      Supported version: 2.3 and later
      Assembly: ComponentPro.Ftp.Android (in ComponentPro.Ftp.Android.dll)

      Xamarin MacXamarin Mac

      Supported version: 2.0.x and later
      Assembly: ComponentPro.Ftp.Mac (in ComponentPro.Ftp.Mac.dll)

      Xamarin iOSXamarin iOS

      Supported version: 5.1.x and later
      Assembly: ComponentPro.Ftp.iOS (in ComponentPro.Ftp.iOS.dll)

      See Also