FtpWebRequest.GetRequestStream メソッド
アセンブリ: System (system.dll 内)

Dim instance As FtpWebRequest Dim returnValue As Stream returnValue = instance.GetRequestStream
現在の要求でサーバーに送信されるデータを格納するために使用する、書き込み可能な Stream インスタンス。

例外の種類 | 条件 |
---|---|
InvalidOperationException | BeginGetRequestStream が呼び出されており、完了していません。 または HTTP プロキシが有効で、WebRequestMethods.Ftp.DownloadFile、WebRequestMethods.Ftp.ListDirectory、または WebRequestMethods.Ftp.ListDirectoryDetails 以外の FTP コマンドを使用しようとしました。 |
WebException | |
ProtocolViolationException | Method プロパティが、WebRequestMethods.Ftp.UploadFile または WebRequestMethods.Ftp.AppendFile に設定されていません。 |

GetRequestStream メソッドを呼び出す前に、要求のプロパティを設定してください。データをストリームに書き込んだら、要求の送信前にそのストリームを閉じる必要があります。
Method プロパティを UploadFile または AppendFile に設定しなかった場合、ストリームは取得できません。
GetRequestStream は、ストリームの待機中にブロックします。これを避けるには、GetRequestStream の代わりに BeginGetRequestStream メソッドを呼び出します。
![]() |
---|
このメンバは、アプリケーションでネットワーク トレースが有効にされている場合にトレース情報を出力します。詳細については、「ネットワークのトレース」を参照してください。 |

要求のデータ ストリームにファイルをコピーし、サーバーに要求を送信して、データをアップロードしてからファイルに追加するコード例を次に示します。
public static bool AppendFileOnServer(string fileName, Uri serverUri) { // The URI described by serverUri should use the ftp:// scheme. // It contains the name of the file on the server. // Example: ftp://contoso.com/someFile.txt. // The fileName parameter identifies the file containing // the data to be appended to the file on the server. if (serverUri.Scheme != Uri.UriSchemeFtp) { return false; } // Get the object used to communicate with the server. FtpWebRequest request = (FtpWebRequest)WebRequest.Create(serverUri); request.Method = WebRequestMethods.Ftp.AppendFile; StreamReader sourceStream = new StreamReader(fileName); byte [] fileContents = Encoding.UTF8.GetBytes(sourceStream.ReadToEnd()); sourceStream.Close(); request.ContentLength = fileContents.Length; // This example assumes the FTP site uses anonymous logon. request.Credentials = new NetworkCredential ("anonymous" ,"janeDoe@contoso.com"); Stream requestStream = request.GetRequestStream(); requestStream.Write(fileContents, 0, fileContents.Length); requestStream.Close(); FtpWebResponse response = (FtpWebResponse) request.GetResponse(); Console.WriteLine("Append status: {0}",response.StatusDescription); response.Close(); return true; }

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からFtpWebRequest.GetRequestStream メソッドを検索する場合は、下記のリンクをクリックしてください。

- FtpWebRequest.GetRequestStream メソッドのページへのリンク