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
FtpWebResponse Class

Encapsulates a File Transfer Protocol (FTP) server's response to a request.

System..::.Object
  System..::.MarshalByRefObject
    System.Net..::.WebResponse
      System.Net..::.FtpWebResponse

Namespace:  System.Net
Assembly:  System (in System.dll)
Visual Basic
Public Class FtpWebResponse _
    Inherits WebResponse _
    Implements IDisposable
C#
public class FtpWebResponse : WebResponse, 
    IDisposable
Visual C++
public ref class FtpWebResponse : public WebResponse, 
    IDisposable
F#
type FtpWebResponse =  
    class
        inherit WebResponse
        interface IDisposable
    end

The FtpWebResponse type exposes the following members.

  NameDescription
Public propertyBannerMessageGets the message sent by the FTP server when a connection is established prior to logon.
Public propertyContentLengthGets the length of the data received from the FTP server. (Overrides WebResponse..::.ContentLength.)
Public propertyContentTypeWhen overridden in a derived class, gets or sets the content type of the data being received. (Inherited from WebResponse.)
Public propertyExitMessageGets the message sent by the server when the FTP session is ending.
Public propertyHeadersInfrastructure. Gets an empty WebHeaderCollection object. (Overrides WebResponse..::.Headers.)
Public propertyIsFromCacheGets a Boolean value that indicates whether this response was obtained from the cache. (Inherited from WebResponse.)
Public propertyIsMutuallyAuthenticatedGets a Boolean value that indicates whether mutual authentication occurred. (Inherited from WebResponse.)
Public propertyLastModifiedGets the date and time that a file on an FTP server was last modified.
Public propertyResponseUriGets the URI that sent the response to the request. (Overrides WebResponse..::.ResponseUri.)
Public propertyStatusCodeGets the most recent status code sent from the FTP server.
Public propertyStatusDescriptionGets text that describes a status code sent from the FTP server.
Public propertyWelcomeMessageGets the message sent by the FTP server when authentication is complete.
Top
  NameDescription
Public methodCloseFrees the resources held by the response. (Overrides WebResponse..::.Close()()().)
Public methodCreateObjRefCreates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object. (Inherited from MarshalByRefObject.)
Public methodEquals(Object)Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetHashCodeServes as a hash function for a particular type. (Inherited from Object.)
Public methodGetLifetimeServiceRetrieves the current lifetime service object that controls the lifetime policy for this instance. (Inherited from MarshalByRefObject.)
Protected methodGetObjectDataInfrastructure. Populates a SerializationInfo with the data that is needed to serialize the target object. (Inherited from WebResponse.)
Public methodGetResponseStreamRetrieves the stream that contains response data sent from an FTP server. (Overrides WebResponse..::.GetResponseStream()()().)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodInitializeLifetimeServiceObtains a lifetime service object to control the lifetime policy for this instance. (Inherited from MarshalByRefObject.)
Protected methodMemberwiseClone()()()Creates a shallow copy of the current Object. (Inherited from Object.)
Protected methodMemberwiseClone(Boolean)Creates a shallow copy of the current MarshalByRefObject object. (Inherited from MarshalByRefObject.)
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Top
  NameDescription
Explicit interface implemetationPrivate methodIDisposable..::.DisposeInfrastructure. When overridden in a derived class, releases all resources used by the WebResponse. (Inherited from WebResponse.)
Explicit interface implemetationPrivate methodISerializable..::.GetObjectDataInfrastructure. Populates a SerializationInfo instance with the data that is needed to serialize WebResponse. (Inherited from WebResponse.)
Top

Instances of FtpWebResponse are obtained by calling the GetResponse method. The returned object must be cast to an FtpWebResponse. When your application no longer needs the FtpWebResponse object, call the Close method to free the resources held by the FtpWebResponse.

The StatusCode property contains the status code returned by the server, and the StatusDescription property returns the status code and a message that describes the status. The values returned by these properties change as the messages are returned by the server.

Any data returned by the request, such as the list of file names returned for a ListDirectory request, is available in the stream returned by the GetResponseStream method. The length of the stream data can be obtained from the ContentLength property.

The following code example sends a request to delete a file on an FTP server and displays the status message from the server's response to the request. For additional examples, see the members of the WebRequestMethods..::.Ftp and FtpWebRequest classes.

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.
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2012 Microsoft. All rights reserved. Terms of Use | Trademarks | Privacy Statement
Page view tracker