This documentation is archived and is not being maintained.

FtpWebRequest.EndGetRequestStream Method

Ends a pending asynchronous operation started with BeginGetRequestStream.

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

Public Overrides Function EndGetRequestStream ( _
	asyncResult As IAsyncResult _
) As Stream
Dim instance As FtpWebRequest 
Dim asyncResult As IAsyncResult 
Dim returnValue As Stream 

returnValue = instance.EndGetRequestStream(asyncResult)


Type: System.IAsyncResult

The IAsyncResult object that was returned when the operation started.

Return Value

Type: System.IO.Stream
A writable Stream instance associated with this instance.


asyncResult is Nothing.


asyncResult was not obtained by calling BeginGetRequestStream.


This method was already called for the operation identified by asyncResult.

If the operation has not completed, the EndGetRequestStream method blocks until the operation completes. To determine whether the operation has completed, check the IsCompleted property before calling EndGetRequestStream.

In addition to the exceptions noted in "Exceptions," EndGetRequestStream rethrows exceptions that were thrown while opening the stream for writing.


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

The following code example demonstrates ending an asynchronous operation to get a request's stream. This code example is part of a larger example provided for the FtpWebRequest class overview.

No code example is currently available or this language may not be supported.
    static void EndGetStreamCallback(IAsyncResult* ar)
        FtpState* state = dynamic_cast<FtpState*> (ar->AsyncState);

        Stream* requestStream = 0;
        // End the asynchronous call to get the request stream.
            requestStream = state->Request->EndGetRequestStream(ar);
            // Copy the file contents to the request stream.
            const int bufferLength = 2048;
            Byte buffer[] = new Byte[bufferLength];
            int count = 0;
            int readBytes = 0;
            FileStream* stream = File::OpenRead(state->FileName);
                readBytes = stream->Read(buffer, 0, bufferLength);
                requestStream->Write(buffer, 0, bufferLength);
                count += readBytes;
            while (readBytes != 0);
            Console::WriteLine (S"Writing {0} bytes to the stream.", __box(count));
            // IMPORTANT: Close the request stream before sending the request.
            // Asynchronously get the response to the upload request.
                new AsyncCallback (EndGetResponseCallback), 
        // Return exceptions to the main application thread.
        catch (Exception* e)
            Console::WriteLine(S"Could not get the request stream.");
            state->OperationException = e;


Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0