Reputation: 143
I try to download more than one file with FtpWebRequest but with only one logging-in to the server. I use KeepAlive property (also with .ConnectionGroupName) but it doesn't work.
The code:
List<string> downloaded = new List<string>();
NetworkCredential networkCredential = new NetworkCredential(_ftpConfiguration.Username, _ftpConfiguration.Password);
foreach (var dataId in requestDataIDs)
{
string uri = "ftp://" + _ftpConfiguration.Host + "//" + dataId;
FtpWebRequest request = (FtpWebRequest)WebRequest.Create(uri);
request.ConnectionGroupName = "myConnection";
request.KeepAlive = true;
request.Method = WebRequestMethods.Ftp.DownloadFile;
request.Credentials = networkCredential;
FtpWebResponse response = (FtpWebResponse)request.GetResponse();
Stream responseStream = response.GetResponseStream();
StreamReader reader = new StreamReader(responseStream);
downloaded.Add(reader.ReadToEnd());
reader.Close();
response.Close();
}
return downloaded;
The "QUIT" message is sent to the server after "reader.ReadToEnd()". When I comment last three lines in the loop, there is no "QUIT" message, but also each request makes logging-in to the server.
I'd like to make it on .NET Core 2.0, but also have tried on .NET Framework 4.6.1 with the same effect.
Do you have any suggestion?
Upvotes: 1
Views: 1208
Reputation: 4379
KeepAlive
is not supported in .Net Core, yet. Per 2.1
it says:
"We don't support connection pooling, so just silently ignore this."
Upvotes: 2