共用方式為


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會導致例外狀況。BeginGetRequestStreamBeginGetResponseGetResponseGetRequestStreamInvalidOperationException

適用於

另請參閱