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
プロパティ値
サーバーに送信する FTP コマンドを含む String 値。 既定値は 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 プロパティは、サーバーに送信されるコマンドを決定します。 Methodを設定するには、WebRequestMethods.Ftp クラスのパブリック フィールド メンバーで定義されている文字列を使用します。 WebRequestMethods.Ftp クラスで定義されている文字列は、Method プロパティでサポートされている唯一のオプションであることに注意してください。 Method プロパティを他の値に設定すると、ArgumentException例外が発生します。
Methodを UploadFile に設定するときは、GetRequestStream メソッドを呼び出す前に設定する必要があります。 これらのメンバーを正しい順序で呼び出すと、要求ストリームを取得しようとしたときに ProtocolViolationException 例外が発生します。
FtpWebRequest オブジェクトに指定する資格情報には、指定したメソッドを実行するためのアクセス許可が必要です。 そうでない場合、FTP コマンドは失敗します。
コマンドの成功または失敗を確認するには、 StatusCode プロパティと StatusDescription プロパティを確認します。