FtpWebRequest.EndGetRequestStream メソッドとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > FtpWebRequest.EndGetRequestStream メソッドの意味・解説 

FtpWebRequest.EndGetRequestStream メソッド

メモ : このメソッドは、.NET Framework version 2.0 で新しく追加されたものです。

BeginGetRequestStream で開始された保留中の非同期操作を終了します。

名前空間: System.Net
アセンブリ: System (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)
public override Stream EndGetRequestStream (
    IAsyncResult asyncResult
)
public:
virtual Stream^ EndGetRequestStream (
    IAsyncResult^ asyncResult
) override
public Stream EndGetRequestStream (
    IAsyncResult asyncResult
)
public override function EndGetRequestStream
 (
    asyncResult : IAsyncResult
) : Stream

パラメータ

asyncResult

操作の開始時に返された IAsyncResult オブジェクト。

戻り値
このインスタンスに関連付けられている、書き込み可能な Stream インスタンス。

例外例外
例外の種類条件

ArgumentNullException

asyncResult が null 参照 (Visual Basic では Nothing) です。

ArgumentException

BeginGetRequestStream の呼び出しで、asyncResult が取得されませんでした。

InvalidOperationException

このメソッドは、asyncResult で識別される操作に対して既に呼び出されています。

解説解説
使用例使用例

要求のストリームを取得するための非同期操作を終了するコード例を次に示します。このコード例は FtpWebRequest クラスの概要で取り上げているコード例の一部分です。

private static void EndGetStreamCallback(IAsyncResult
 ar)
{
    FtpState state = (FtpState) ar.AsyncState;
    
    Stream requestStream = null;
    // End the asynchronous call to get the request stream.
    try
    {
        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);
        do
        {
            readBytes = stream.Read(buffer, 0, bufferLength);
            requestStream.Write(buffer, 0, readBytes);
            count += readBytes;
        }
        while (readBytes != 0);
        Console.WriteLine ("Writing {0} bytes to the stream.", count);
        // IMPORTANT: Close the request stream before sending the request.
        requestStream.Close();
        // Asynchronously get the response to the upload request.
        state.Request.BeginGetResponse(
            new AsyncCallback (EndGetResponseCallback), 
            state
        );
    } 
    // Return exceptions to the main application thread.
    catch (Exception e)
    {
        Console.WriteLine("Could not get the request stream.");
        state.OperationException = e;
        state.OperationComplete.Set();
        return;
    }
   
}
private:
   static void EndGetStreamCallback( IAsyncResult^
 ar )
   {
      FtpState^ state = dynamic_cast<FtpState^>(ar->AsyncState);
      Stream^ requestStream = nullptr;

      // End the asynchronous call to get the request stream.
      try
      {
         requestStream = state->Request->EndGetRequestStream( ar );

         // Copy the file contents to the request stream.
         const int bufferLength = 2048;
         array<Byte>^buffer = gcnew array<Byte>(bufferLength);
         int count = 0;
         int readBytes = 0;
         FileStream^ stream = File::OpenRead( state->FileName );
         do
         {
            readBytes = stream->Read( buffer, 0, bufferLength );
            requestStream->Write( buffer, 0, bufferLength );
            count += readBytes;
         }
         while ( readBytes != 0 );
         Console::WriteLine( "Writing {0} bytes to the stream.", count
 );

         // IMPORTANT: Close the request stream before sending the request.
         requestStream->Close();

         // Asynchronously get the response to the upload request.
         state->Request->BeginGetResponse( gcnew AsyncCallback( EndGetResponseCallback
 ), state );
      }
      // Return exceptions to the main application thread.
      catch ( Exception^ e ) 
      {
         Console::WriteLine( "Could not get the request stream."
 );
         state->OperationException = e;
         state->OperationComplete->Set();
         return;
      }
   }
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
FtpWebRequest クラス
FtpWebRequest メンバ
System.Net 名前空間
FtpWebResponse
FtpStatusCode 列挙体
WebRequestMethods.Ftp
WebRequest
WebResponse
WebClient



英和和英テキスト翻訳

英語⇒日本語日本語⇒英語

辞書ショートカット

すべての辞書の索引

FtpWebRequest.EndGetRequestStream メソッドのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



FtpWebRequest.EndGetRequestStream メソッドのページの著作権

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2026 Microsoft.All rights reserved.

©2026 GRAS Group, Inc.RSS