FtpWebRequest.Method Proprietà

Definizione

Ottiene o imposta il comando da inviare al server FTP.

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

Valore della proprietà

Valore String che contiene il comando FTP da inviare al server. Il valore predefinito è DownloadFile.

Eccezioni

È stato specificato un nuovo valore per questa proprietà per una richiesta già in corso.

Il metodo non è valido.

-oppure-

Il metodo non è supportato.

-oppure-

Sono stati specificati più metodi.

Esempio

Nell'esempio di codice seguente questa proprietà viene impostata su DeleteFile.

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;
}

Commenti

La Method proprietà determina il comando inviato al server. È possibile impostare l'oggetto Method usando le stringhe definite nei membri del campo pubblico della WebRequestMethods.Ftp classe. Si noti che le stringhe definite nella WebRequestMethods.Ftp classe sono le uniche opzioni supportate per la Method proprietà. L'impostazione della proprietà su qualsiasi altro valore comporterà un'eccezione MethodArgumentException .

Quando si imposta Method su UploadFile, è necessario eseguire questa operazione prima di chiamare il GetRequestStream metodo. L'errore di chiamare questi membri nell'ordine corretto causa un'eccezione ProtocolViolationException quando si tenta di ottenere il flusso di richiesta.

Le credenziali fornite per l'oggetto devono disporre dell'autorizzazione FtpWebRequest per eseguire il metodo specificato. In caso contrario, il comando FTP ha esito negativo.

Per determinare l'esito positivo o negativo di un comando, controllare le StatusCode proprietà e StatusDescription .

Si applica a

Vedi anche