FtpWebRequest.Method 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
接收或設定指令傳送到 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
屬性值
一個 String 包含 FTP 指令的值,用來傳送給伺服器。 預設值為 DownloadFile。
例外狀況
為已進行中的請求指定了該屬性的新值。
範例
以下程式碼範例將此屬性設定為 DeleteFile。
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;
}
備註
屬性決定 Method 了要傳送給伺服器的指令。 你可以透過類別中公開欄位WebRequestMethods.Ftp成員中定義的字串來設定 。Method 請注意,類別中定義的 WebRequestMethods.Ftp 字串是該屬性唯一支援的選項 Method 。 將屬性設 Method 為其他值時,會產生 ArgumentException 例外。
當設定 Method 為 UploadFile時,必須先設定 ,然後再呼叫該 GetRequestStream 方法。 若未按正確順序呼叫這些成員,嘗試取得請求串流時會產生 ProtocolViolationException 例外。
物件所提供的 FtpWebRequest 憑證必須具備執行指定方法的權限。 如果沒有,FTP 指令就會失敗。
要判斷指令的成功或失敗,請檢查 StatusCode 和 StatusDescription 屬性。