FtpWebRequest::Abort Method ()
.NET Framework (current version)
Terminates an asynchronous FTP operation.
Assembly: System (in System.dll)
If there is no operation in progress, this method does nothing. If a file transfer is in progress, this method terminates the transfer.
Note |
|---|
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.
public: 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() ); sourceStream->Close(); // 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" ) ) { request->Abort(); Console::WriteLine( "Request aborted" ); return; } }
.NET Framework
Available since 2.0
Available since 2.0
Show:
