FtpWebRequest::Abort Method ()


The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Terminates an asynchronous FTP operation.

Namespace:   System.Net
Assembly:  System (in System.dll)

virtual void Abort() override

If there is no operation in progress, this method does nothing. If a file transfer is in progress, this method terminates the transfer.


This member outputs trace information when you enable network tracing in your application. For more information, see Network Tracing in the .NET Framework.

The following code example demonstrates how the user can terminate an asynchronous upload of a file from the local directory to the server.

   void AbortUpload( String^ fileName, String^ serverUri )
      request = dynamic_cast<FtpWebRequest^>(WebRequest::Create( serverUri ));
      request->Method = WebRequestMethods::Ftp::UploadFile;

      // Get the file to be uploaded and convert it to bytes.
      StreamReader^ sourceStream = gcnew StreamReader( fileName );
      fileContents = Encoding::UTF8->GetBytes( sourceStream->ReadToEnd() );

      // Set the content length to the number of bytes in the file.
      request->ContentLength = fileContents->Length;

      // Asynchronously get the stream for the file contents.
      IAsyncResult^ ar = request->BeginGetRequestStream( gcnew AsyncCallback( this, &AsynchronousFtpUpLoader::EndGetStreamCallback ), nullptr );
      Console::WriteLine( "Getting the request stream asynchronously..." );
      Console::WriteLine( "Press 'a' to abort the upload or any other key to continue" );
      String^ input = Console::ReadLine();
      if ( input->Equals( "a" ) )
         Console::WriteLine( "Request aborted" );

.NET Framework
Available since 2.0
Return to top