Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Reuse FtpWebRequest Connection

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

like image 473
Feyyaz Avatar asked Aug 20 '11 14:08

Feyyaz


1 Answers

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

  • How to improve the Performance of FtpWebRequest?
like image 57
Damith Avatar answered Oct 18 '22 00:10

Damith