FtpWebRequest.KeepAlive Property

Definition

Gets or sets a Boolean value that specifies whether the control connection to the FTP server is closed after the request completes.

C#
public bool KeepAlive { get; set; }

Property Value

true if the connection to the server should not be destroyed; otherwise, false. The default value is true.

Exceptions

A new value was specified for this property for a request that is already in progress.

Examples

The following code example retrieves and displays property values for a specified FtpWebRequest object.

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

Remarks

When the KeepAlive property is set to false, the control connection is closed when you call the Close method.

Changing KeepAlive after calling the GetRequestStream, BeginGetRequestStream, GetResponse, or BeginGetResponse method causes an InvalidOperationException exception.

Applies to

Product Versions
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

See also