FtpWebResponse FtpWebResponse FtpWebResponse FtpWebResponse Class

定义

封装文件传输协议 (FTP) 服务器对请求的响应。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
type FtpWebResponse = class
    inherit WebResponse
Public Class FtpWebResponse
Inherits WebResponse
继承

示例

下面的代码示例将发送一个请求, 以删除 FTP 服务器上的文件, 并显示服务器对请求的响应中的状态消息。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. 有关其他示例, 请参见WebRequestMethods.FtpFtpWebRequest类的成员。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;
}

注解

的实例FtpWebResponse是通过GetResponse调用方法获取的。Instances of FtpWebResponse are obtained by calling the GetResponse method. 返回的对象必须强制转换为FtpWebResponseThe returned object must be cast to an FtpWebResponse. 当应用程序不再需要FtpWebResponse对象时, 请Close调用方法以释放由FtpWebResponse占用的资源。When your application no longer needs the FtpWebResponse object, call the Close method to free the resources held by the FtpWebResponse.

属性包含服务器返回的状态代码, StatusDescription属性返回状态代码和描述状态的消息。 StatusCodeThe 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.

请求返回的任何数据 (如为ListDirectory请求返回的文件名列表) 都可用于GetResponseStream方法返回的流中。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. 可以从ContentLength属性获取流数据的长度。The length of the stream data can be obtained from the ContentLength property.

属性

BannerMessage BannerMessage BannerMessage BannerMessage

获取在登录前建立连接时 FTP 服务器发送的消息。Gets the message sent by the FTP server when a connection is established prior to logon.

ContentLength ContentLength ContentLength ContentLength

获取从 FTP 服务器上接收的数据的长度。Gets the length of the data received from the FTP server.

ContentType ContentType ContentType ContentType
ExitMessage ExitMessage ExitMessage ExitMessage

获取 FTP 会话结束时服务器发送的消息。Gets the message sent by the server when the FTP session is ending.

Headers Headers Headers Headers

获取空 WebHeaderCollection 对象。Gets an empty WebHeaderCollection object.

IsFromCache IsFromCache IsFromCache IsFromCache

获取一个 Boolean 值,该值指示此响应是否为从缓存中获取的。Gets a Boolean value that indicates whether this response was obtained from the cache.

(Inherited from WebResponse)
IsMutuallyAuthenticated IsMutuallyAuthenticated IsMutuallyAuthenticated IsMutuallyAuthenticated

获取一个 Boolean 值,该值指示是否发生了相互身份验证。Gets a Boolean value that indicates whether mutual authentication occurred.

(Inherited from WebResponse)
LastModified LastModified LastModified LastModified

获取 FTP 服务器上的文件的上次修改日期和时间。Gets the date and time that a file on an FTP server was last modified.

ResponseUri ResponseUri ResponseUri ResponseUri

获取对请求发送响应的 URI。Gets the URI that sent the response to the request.

StatusCode StatusCode StatusCode StatusCode

获取从 FTP 服务器上发送的最新状态代码。Gets the most recent status code sent from the FTP server.

StatusDescription StatusDescription StatusDescription StatusDescription

获取描述从 FTP 服务器发送的状态代码的文本。Gets text that describes a status code sent from the FTP server.

SupportsHeaders SupportsHeaders SupportsHeaders SupportsHeaders

获取一个值,该值指示 Headers 属性是否由 FtpWebResponse 实例支持。Gets a value that indicates whether the Headers property is supported by the FtpWebResponse instance.

WelcomeMessage WelcomeMessage WelcomeMessage WelcomeMessage

获取身份验证完成时 FTP 服务器发送的消息。Gets the message sent by the FTP server when authentication is complete.

方法

Close() Close() Close() Close()

释放响应所持有的资源。Frees the resources held by the response.

CreateObjRef(Type) 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() Dispose()

释放 WebResponse 对象使用的非托管资源。Releases the unmanaged resources used by the WebResponse object.

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

释放由 WebResponse 对象使用的非托管资源,并可根据需要释放托管资源。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) Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

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

作为默认哈希函数。Serves as the default hash function.

(Inherited from Object)
GetLifetimeService() 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) GetObjectData(SerializationInfo, StreamingContext)

使用序列化目标对象所需的数据填充 SerializationInfoPopulates a SerializationInfo with the data that is needed to serialize the target object.

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

检索包含从 FTP 服务器上发送的响应数据的流。Retrieves the stream that contains response data sent from an FTP server.

GetType() GetType() GetType() GetType()

获取当前实例的 TypeGets the Type of the current instance.

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

获取生存期服务对象来控制此实例的生存期策略。Obtains a lifetime service object to control the lifetime policy for this instance.

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

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

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

创建当前 MarshalByRefObject 对象的浅表副本。Creates a shallow copy of the current MarshalByRefObject object.

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

返回表示当前对象的字符串。Returns a string that represents the current object.

(Inherited from Object)

显式界面实现

IDisposable.Dispose() IDisposable.Dispose() IDisposable.Dispose() IDisposable.Dispose()

当在派生类中被重写时,释放 WebResponse 使用的所有资源。When overridden in a derived class, releases all resources used by the WebResponse.

(Inherited from WebResponse)
ISerializable.GetObjectData(SerializationInfo, StreamingContext) ISerializable.GetObjectData(SerializationInfo, StreamingContext) ISerializable.GetObjectData(SerializationInfo, StreamingContext) ISerializable.GetObjectData(SerializationInfo, StreamingContext)

使用序列化 SerializationInfo 所需的数据来填充 WebResponse 实例。Populates a SerializationInfo instance with the data that is needed to serialize WebResponse.

(Inherited from WebResponse)

适用于

另请参阅