FtpWebRequest.KeepAlive 属性

定义

获取或设置一个 Boolean 值,该值指定在请求完成之后是否关闭到 FTP 服务器的控制连接。

public:
 property bool KeepAlive { bool get(); void set(bool value); };
public bool KeepAlive { get; set; }
member this.KeepAlive : bool with get, set
Public Property KeepAlive As Boolean

属性值

如果不应销毁到服务器的连接,则为 true;否则为 false。 默认值是 true

例外

对于一个已在进行的请求为此属性指定了一个新值。

示例

下面的代码示例检索并显示指定 FtpWebRequest 对象的属性值。

Console::WriteLine( "Passive: {0}  Keep alive: {1}  Binary: {2} Timeout: {3}.", request->UsePassive, request->KeepAlive, request->UseBinary, request->Timeout == -1 ? "none" : request->Timeout.ToString() );
Console.WriteLine("Passive: {0}  Keep alive: {1}  Binary: {2} Timeout: {3}.",
    request.UsePassive,
    request.KeepAlive,
    request.UseBinary,
    request.Timeout == -1 ? "none" : request.Timeout.ToString()
);

注解

当 属性 KeepAlive 设置为 false时,调用 Close 方法时,将关闭控件连接。

调用 、、 或 方法后更改KeepAlive会导致InvalidOperationException异常。BeginGetResponseGetResponseBeginGetRequestStreamGetRequestStream

适用于

另请参阅