FtpWebRequest.GetResponse Yöntem

Tanım

FTP sunucusu yanıtını döndürür.

public:
 override System::Net::WebResponse ^ GetResponse();
public override System.Net.WebResponse GetResponse ();
override this.GetResponse : unit -> System.Net.WebResponse
Public Overrides Function GetResponse () As WebResponse

Döndürülenler

Örnek WebResponse içeren bir FtpWebResponse başvuru. Bu nesne, FTP sunucusunun isteğe verdiği yanıtı içerir.

Özel durumlar

GetResponse() veya BeginGetResponse(AsyncCallback, Object) bu örnek için zaten çağrıldı.

-veya-

HTTP proxy'si etkinleştirildi ve , ListDirectoryveya ListDirectoryDetailsdışında DownloadFilebir FTP komutu kullanmayı denediniz.

EnableSsl olarak ayarlanır true, ancak sunucu bu özelliği desteklemez.

-veya-

bir Timeout belirtildi ve zaman aşımı süresi doldu.

Örnekler

Aşağıdaki kod örneği, bir dosyanın isteğin veri akışına kopyalanmasını ve sunucuya bir dosyaya veri ekleme isteği göndermeyi gösterir. Örnek, isteği göndermeyi ve yanıt sunucu tarafından döndürülene kadar engellemeyi çağırır GetResponse .

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 = dynamic_cast<FtpWebRequest^>(WebRequest::Create( serverUri ));
   request->Method = WebRequestMethods::Ftp::AppendFile;
   StreamReader^ sourceStream = gcnew StreamReader( fileName );
   array<Byte>^fileContents = Encoding::UTF8->GetBytes( sourceStream->ReadToEnd() );
   sourceStream->Close();
   request->ContentLength = fileContents->Length;

   // This example assumes the FTP site uses anonymous logon.
   request->Credentials = gcnew NetworkCredential( "anonymous","janeDoe@contoso.com" );
   Stream^ requestStream = request->GetRequestStream();
   requestStream->Write( fileContents, 0, fileContents->Length );
   requestStream->Close();
   FtpWebResponse^ response = dynamic_cast<FtpWebResponse^>(request->GetResponse());
   Console::WriteLine( "Append status: {0}", response->StatusDescription );
   response->Close();
   return true;
}
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;
}

Açıklamalar

FTP'ye özgü özelliklere erişmek için, bu yöntem tarafından döndürülen nesneyi 'ye FtpWebResponseatamanız WebResponse gerekir.

GetResponse bir denetim bağlantısı kurulmasına neden olur ve veri bağlantısı da oluşturabilir. GetResponse yanıt alınana kadar engeller. Bunu önlemek için yerine ve EndGetResponse yöntemlerini GetResponseçağırarak BeginGetResponse bu işlemi zaman uyumsuz olarak gerçekleştirebilirsiniz.

Proxy Özellik doğrudan veya bir yapılandırma dosyasında ayarlanırsa, FTP sunucusuyla iletişim ara sunucu üzerinden yapılır.

oluşturulursa WebException , sunucudan Response yanıtı belirlemek için özel durumun ve Status özelliklerini kullanın.

Uygulamanızda ağ izlemeyi etkinleştirdiğinizde, bu üye izleme bilgilerini çıkarır. Daha fazla bilgi için .NET Framework ağ izleme bölümüne bakın.

Not

Aynı yanıt nesnesini döndürmek için GetResponse birden çok çağrı yapılır; istek yeniden yapılmaz.

Arayanlara Notlar

Bu yöntem ağ trafiği oluşturur.

Şunlara uygulanır

Ayrıca bkz.