How to Reuse FtpWebRequest Connection
Asked Answered
A

1

8

I need to list thousands of files on FTP server, and delete the necessary ones. As you can guess, performance is essential, so I need a way to reuse the FTP connection.

There is not enough explanation on MSDN about the connection usage of FtpWebRequests! It only says "Multiple FtpWebRequests reuse existing connections, if possible." What does "if possible" mean? I want to control when to close connection, simple as that! Any idea?

Regards

Abijah answered 20/8, 2011 at 14:7 Comment(0)
O
9

Previous connections to the server are reused if possible as long as the KeepAlive parameter to the HttpWebRequest object is set to true.This optimization happens underneath the creation and use of multiple HttpWebRequest objects.

With respect to multithreaded operations, there is a limit on the number of concurrent connection to a particular host.

System.Net.ServicePointManager.DefaultConnectionLimit can used to increase concurrent connections

Osanna answered 20/8, 2011 at 14:39 Comment(2)
OK, but when does it close the connection?Abijah
GC will take care of closing the HttpWebRequest but you need to close the HttpWebResponseOsanna

© 2022 - 2024 — McMap. All rights reserved.