Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Downloading files from multiple directory in one FTP Connection with FTPWebRequest in .NET

Is it possible to change the Path of the FTP session once the Session is Open. The reason I want to do this is to avoid to open the multiple FTP connection. The whole purpose is to download the files located in the FTP site in a single FTP connection. For example, in single FTP connection, I want download the contens from all the directory located in the FTP site. Currently, I have project that is failing everyday because It makes multiple connections to the FTP site to download files from different directory . For example, making more than 80 connections in 1 minutes.

What are restrictions of the FTPWebRequest in .NET

like image 769
Shiva Avatar asked Feb 15 '10 04:02

Shiva


People also ask

How do I download multiple files from an FTP site?

To download multiple files from FTP server, we use mget command. Using that command we can download more than one file at a time. To download multiple files specify wildcard character for specifying directory name do download all files from the directory.


1 Answers

As per the documentation for FtpWebRequest:

Multiple FtpWebRequests reuse existing connections, if possible.

Admittedly that does not really tell you much but if you look at the documentation for the ConnectionGroupName property, it tells you that you can specify the same ConnectionGroupName for multiple requests in order to reuse the connection.

Here is more information on managing connections in .NET.

Alternatively, you should be able to use the WebClient class to issue multiple related FTP requests and although I can't say for sure, I would imagine that it would reuse the connection. Unlike FtpWebRequest which can only be used once, WebClient can be used to make multiple requests.

like image 189
Josh Avatar answered Nov 15 '22 03:11

Josh