次の方法で共有


FtpWebRequest.Method プロパティ

定義

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 します。

を にUploadFile設定Methodする場合は、 メソッドを呼び出す前にGetRequestStream行う必要があります。 これらのメンバーを正しい順序で呼び出すと、要求ストリームを ProtocolViolationException 取得しようとすると例外が発生します。

オブジェクトに指定された資格情報には、 FtpWebRequest 指定されたメソッドを実行するためのアクセス許可が必要です。 そうでない場合、FTP コマンドは失敗します。

コマンドの成功または失敗を確認するには、 プロパティと プロパティをStatusCodeStatusDescription確認します。

適用対象

こちらもご覧ください