Export (0) Print
Expand All

FtpWebRequest.Method Property

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

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

public:
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)

Not applicable.

Property Value

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

Exception typeCondition

InvalidOperationException

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

ArgumentException

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. You set the Method by using the strings defined in the public field members of the WebRequestMethods.Ftp class. Note that the strings defined in the WebRequestMethods.Ftp class are the only supported options for the Method property. Setting the Method property to any other value will result in an ArgumentException exception.

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.

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);  
    response.Close();
    return true;
}

Windows 98, Windows Server 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 Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0

Community Additions

ADD
Show:
© 2014 Microsoft