FtpWebRequest.Method Özellik

Tanım

KOMUTU FTP sunucusuna gönderecek şekilde alır veya ayarlar.

public:
 virtual property System::String ^ Method { System::String ^ get(); void set(System::String ^ value); };
public override string Method { get; set; }
member this.Method : string with get, set
Public Overrides Property Method As String

Özellik Değeri

String Sunucuya gönderilecek FTP komutunu içeren değer. DownloadFile varsayılan değerdir.

Özel durumlar

Devam etmekte olan bir istek için bu özellik için yeni bir değer belirtildi.

Yöntem geçersiz.

-veya-

yöntemi desteklenmiyor.

-veya-

Birden çok yöntem belirtildi.

Örnekler

Aşağıdaki kod örneği bu özelliği olarak DeleteFileayarlar.

static bool DeleteFileOnServer( Uri^ serverUri )
{
   // The serverUri parameter should use the ftp:// scheme.
   // It contains the name of the server file that is to be deleted.
   // Example: ftp://contoso.com/someFile.txt.
   // 
   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::DeleteFile;
   FtpWebResponse^ response = dynamic_cast<FtpWebResponse^>(request->GetResponse());
   Console::WriteLine( "Delete status: {0}", response->StatusDescription );
   response->Close();
   return true;
}
public static bool DeleteFileOnServer(Uri serverUri)
{
    // The serverUri parameter should use the ftp:// scheme.
    // It contains the name of the server file that is to be deleted.
    // Example: ftp://contoso.com/someFile.txt.
    //

    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.DeleteFile;

    FtpWebResponse response = (FtpWebResponse) request.GetResponse();
    Console.WriteLine("Delete status: {0}",response.StatusDescription);
    response.Close();
    return true;
}

Açıklamalar

Method özelliği, sunucuya hangi komutun gönderileceğini belirler. sınıfının ortak alan üyelerinde WebRequestMethods.Ftp tanımlanan dizeleri kullanarak öğesini ayarlarsınızMethod. sınıfında tanımlanan WebRequestMethods.Ftp dizelerin özelliği için Method desteklenen tek seçenekler olduğunu unutmayın. özelliğini başka Method bir değere ayarlamak bir ArgumentException özel durumla sonuçlanır.

olarak ayarlandığında MethodUploadFile, yöntemini çağırmadan GetRequestStream önce bunu yapmanız gerekir. Bu üyelerin doğru sırada çağrılamaması, istek akışını almaya çalıştığınızda bir ProtocolViolationException özel duruma neden olur.

Nesne için FtpWebRequest sağlanan kimlik bilgilerinin belirtilen yöntemi gerçekleştirme izni olmalıdır. Aksi takdirde FTP komutu başarısız olur.

Bir komutun başarısını veya başarısızlığını belirlemek için ve StatusDescription özelliklerini denetleyinStatusCode.

Şunlara uygulanır

Ayrıca bkz.