FtpWebResponse.GetResponseStream FtpWebResponse.GetResponseStream FtpWebResponse.GetResponseStream FtpWebResponse.GetResponseStream Method
定義
FTP サーバーから送信された応答データを格納しているストリームを取得します。Retrieves the stream that contains response data sent from an FTP server.
public:
override System::IO::Stream ^ GetResponseStream();
public override System.IO.Stream GetResponseStream ();
override this.GetResponseStream : unit -> System.IO.Stream
Public Overrides Function GetResponseStream () As Stream
戻り値
応答で返されたデータを格納している読み取り可能な Stream インスタンス。サーバーによって返された応答データがない場合は Null。A readable Stream instance that contains data returned with the response; otherwise, Null if no response data was returned by the server.
例外
応答でデータ ストリームが返されませんでした。The response did not return a data stream.
例
次のコード例では、応答ストリームの取得を示しています、ListDirectory要求。The following code example demonstrates getting the response stream for a ListDirectory request.
static bool ListFilesOnServer( Uri^ serverUri )
{
// The serverUri should start with the ftp:// scheme.
if ( serverUri->Scheme != Uri::UriSchemeFtp )
{
return false;
}
// Get the object used to communicate with the server.
FtpWebRequest^ request = dynamic_cast<FtpWebRequest^>(WebRequest::Create( serverUri ));
request->Method = WebRequestMethods::Ftp::ListDirectory;
// Get the ServicePoint object used for this request, and limit it to one connection.
// In a real-world application you might use the default number of connections (2),
// or select a value that works best for your application.
ServicePoint^ sp = request->ServicePoint;
Console::WriteLine( "ServicePoint connections = {0}.", sp->ConnectionLimit );
sp->ConnectionLimit = 1;
FtpWebResponse^ response = dynamic_cast<FtpWebResponse^>(request->GetResponse());
// The following streams are used to read the data returned from the server.
Stream^ responseStream = nullptr;
StreamReader^ readStream = nullptr;
try
{
responseStream = response->GetResponseStream();
readStream = gcnew StreamReader( responseStream,System::Text::Encoding::UTF8 );
if ( readStream != nullptr )
{
// Display the data received from the server.
Console::WriteLine( readStream->ReadToEnd() );
}
Console::WriteLine( "List status: {0}", response->StatusDescription );
}
finally
{
if ( readStream != nullptr )
{
readStream->Close();
}
if ( response != nullptr )
{
response->Close();
}
}
return true;
}
public static bool ListFilesOnServer(Uri serverUri)
{
// The serverUri should start with the ftp:// scheme.
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.ListDirectory;
// Get the ServicePoint object used for this request, and limit it to one connection.
// In a real-world application you might use the default number of connections (2),
// or select a value that works best for your application.
ServicePoint sp = request.ServicePoint;
Console.WriteLine("ServicePoint connections = {0}.", sp.ConnectionLimit);
sp.ConnectionLimit = 1;
FtpWebResponse response = (FtpWebResponse) request.GetResponse();
// The following streams are used to read the data returned from the server.
Stream responseStream = null;
StreamReader readStream = null;
try
{
responseStream = response.GetResponseStream();
readStream = new StreamReader(responseStream, System.Text.Encoding.UTF8);
if (readStream != null)
{
// Display the data received from the server.
Console.WriteLine(readStream.ReadToEnd());
}
Console.WriteLine("List status: {0}",response.StatusDescription);
}
finally
{
if (readStream != null)
{
readStream.Close();
}
if (response != null)
{
response.Close();
}
}
return true;
}
注釈
データの読み込み後にストリームを閉じる必要があります。After reading the data, you must close the stream. 閉じるときに自動的に、ストリームが閉じている、FtpWebResponseそれを含んでいるオブジェクト。The stream is automatically closed when you close the FtpWebResponse object that contains it.
要求メソッドがない限り、例外がスローされたDownloadFileまたはListDirectoryします。An exception is thrown unless the request method is DownloadFile or ListDirectory.
適用対象
.NET Core
.NET Framework
.NET Standard
Xamarin.Android
Xamarin.iOS
Xamarin.Mac
こちらもご覧ください
フィードバック
お客様のご意見をお寄せください。 お寄せいただく内容の種類を選択:
このフィードバック システムは、GitHub Issues を利用して構築されています。 詳しくは、ブログをご覧ください。
フィードバックを読み込んでいます...