FtpWebResponse FtpWebResponse FtpWebResponse Class

Definition

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

public ref class FtpWebResponse : System::Net::WebResponse
public class FtpWebResponse : System.Net.WebResponse
Public Class FtpWebResponse
Inherits WebResponse
Inheritance

Examples

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.

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;
}
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;
}

Remarks

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.

Properties

BannerMessage BannerMessage BannerMessage

Gets the message sent by the FTP server when a connection is established prior to logon.

ContentLength ContentLength ContentLength

Gets the length of the data received from the FTP server.

ContentType ContentType ContentType
ExitMessage ExitMessage ExitMessage

Gets the message sent by the server when the FTP session is ending.

Headers Headers Headers

Gets an empty WebHeaderCollection object.

IsFromCache IsFromCache IsFromCache

Gets a Boolean value that indicates whether this response was obtained from the cache.

(Inherited from WebResponse)
IsMutuallyAuthenticated IsMutuallyAuthenticated IsMutuallyAuthenticated

Gets a Boolean value that indicates whether mutual authentication occurred.

(Inherited from WebResponse)
LastModified LastModified LastModified

Gets the date and time that a file on an FTP server was last modified.

ResponseUri ResponseUri ResponseUri

Gets the URI that sent the response to the request.

StatusCode StatusCode StatusCode

Gets the most recent status code sent from the FTP server.

StatusDescription StatusDescription StatusDescription

Gets text that describes a status code sent from the FTP server.

SupportsHeaders SupportsHeaders SupportsHeaders

Gets a value that indicates whether the Headers property is supported by the FtpWebResponse instance.

WelcomeMessage WelcomeMessage WelcomeMessage

Gets the message sent by the FTP server when authentication is complete.

Methods

Close() Close() Close()

Frees the resources held by the response.

CreateObjRef(Type) CreateObjRef(Type) CreateObjRef(Type)

Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.

(Inherited from MarshalByRefObject)
Dispose() Dispose() Dispose()

Releases the unmanaged resources used by the WebResponse object.

(Inherited from WebResponse)
Dispose(Boolean) Dispose(Boolean) Dispose(Boolean)

Releases the unmanaged resources used by the WebResponse object, and optionally disposes of the managed resources.

(Inherited from WebResponse)
Equals(Object) Equals(Object) Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode() GetHashCode() GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetLifetimeService() GetLifetimeService() GetLifetimeService()

Retrieves the current lifetime service object that controls the lifetime policy for this instance.

(Inherited from MarshalByRefObject)
GetObjectData(SerializationInfo, StreamingContext) GetObjectData(SerializationInfo, StreamingContext) GetObjectData(SerializationInfo, StreamingContext)

Populates a SerializationInfo with the data that is needed to serialize the target object.

(Inherited from WebResponse)
GetResponseStream() GetResponseStream() GetResponseStream()

Retrieves the stream that contains response data sent from an FTP server.

GetType() GetType() GetType()

Gets the Type of the current instance.

(Inherited from Object)
InitializeLifetimeService() InitializeLifetimeService() InitializeLifetimeService()

Obtains a lifetime service object to control the lifetime policy for this instance.

(Inherited from MarshalByRefObject)
MemberwiseClone() MemberwiseClone() MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
MemberwiseClone(Boolean) MemberwiseClone(Boolean) MemberwiseClone(Boolean)

Creates a shallow copy of the current MarshalByRefObject object.

(Inherited from MarshalByRefObject)
ToString() ToString() ToString()

Returns a string that represents the current object.

(Inherited from Object)

Explicit Interface Implementations

ISerializable.GetObjectData(SerializationInfo, StreamingContext) ISerializable.GetObjectData(SerializationInfo, StreamingContext) ISerializable.GetObjectData(SerializationInfo, StreamingContext)

Populates a SerializationInfo instance with the data that is needed to serialize WebResponse.

(Inherited from WebResponse)

Applies to

See Also