FtpWebRequest.Method Property

Note: This property is new in the .NET Framework version 2.0.

Gets or sets the command to send to the FTP server.

Namespace: System.Net
Assembly: System (in system.dll)

virtual property String^ Method {
	String^ get () override;
	void set (String^ value) override;
/** @property */
public String get_Method ()

/** @property */
public void set_Method (String value)

public override function get Method () : String

public override function set Method (value : String)

Property Value

A String value that contains the FTP command to send to the server. The default value is DownloadFile.

Exception typeCondition


A new value was specified for this property for a request that is already in progress.


The method is invalid.

- or -

The method is not supported.

- or -

Multiple methods were specified.

The Method property determines which command is sent to the server. Typically, you set Method by using the strings defined in the WebRequestMethods.Ftp structure. When setting Method to UploadFile, you must do so before calling the GetRequestStream method. Failure to call these members in the correct order causes a ProtocolViolationException exception when you attempt to get the request stream.

The credentials supplied for the FtpWebRequest object must have permission to perform the specified method. If not, the FTP command fails.

You can set Method to any command recognized by the server and use the FtpWebRequest object to send the command. This works as expected only if the command does not require you to send data and the server does not send data in response to the request.

You must not send any command that alters the state of the connection. For example, do not use the "MODE", "PASV", or "PORT" commands. Using commands that change the state of the connection can leave the request and the underlying connection in an unusable state. To determine the success or failure of a command, check the Status and StatusDescription properties.

The following code example sets this property to 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);  
    return true;

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0