Click to Rate and Give Feedback
TechNet
TechNet Library
Collapse All/Expand All Collapse All
This page is specific to
Microsoft Visual Studio 2010/.NET Framework 4

Other versions are also available for the following:
.NET Framework Class Library
FtpWebRequest..::.Method Property

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

Namespace:  System.Net
Assembly:  System (in System.dll)
Visual Basic
Public Overrides Property Method As String
C#
public override string Method { get; set; }
Visual C++
public:
virtual property String^ Method {
    String^ get () override;
    void set (String^ value) override;
}
F#
abstract Method : string with get, set
override Method : string with get, set

Property Value

Type: System..::.String
A String value that contains the FTP command to send to the server. The default value is DownloadFile.
ExceptionCondition
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 StatusCode and StatusDescription properties.

The following code example sets this property to DeleteFile.

Visual Basic
Public Shared Function DeleteFileOnServer(ByVal serverUri As Uri) As Boolean
    ' 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 Then
        Return False
    End If
    ' Get the object used to communicate with the server.
    Dim request As FtpWebRequest = CType(WebRequest.Create(serverUri), FtpWebRequest)
    request.Method = WebRequestMethods.Ftp.DeleteFile

    Dim response As FtpWebResponse = CType(request.GetResponse(), FtpWebResponse)
    Console.WriteLine("Delete status: {0}", response.StatusDescription)
    response.Close()
    Return True
End Function
C#
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;
}
Visual C++
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 = dynamic_cast<FtpWebRequest^>(WebRequest::Create( serverUri ));
   request->Method = WebRequestMethods::Ftp::DeleteFile;
   FtpWebResponse^ response = dynamic_cast<FtpWebResponse^>(request->GetResponse());
   Console::WriteLine( "Delete status: {0}", response->StatusDescription );
   response->Close();
   return true;
}

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Possible Values      Yván Ecarri   |   Edit   |   Show History

Values are listed in http://msdn.microsoft.com/en-us/library/system.net.ftpwebrequest.method.aspx

Tags What's this?: Add a tag
Flag as ContentBug
Processing
© 2012 Microsoft. All rights reserved. Terms of Use | Trademarks | Privacy Statement
Page view tracker