FtpWebRequest connection
If not there's a way to have a persistent connection other than use a simple Socket and implementing the Ftp RFC?
Thanks in advance for your help
If not there's a way to have a persistent connection other than use a simple Socket and implementing the Ftp RFC?
Thanks in advance for your help
Yes, I beleive the command connection (to port 21) is persistent. Try the following code:
FtpWebRequest req = (FtpWebRequest)WebRequest.Create(ftp://somehost.com/test/file1.txt);
FtpWebResponse resp = (FtpWebResponse)req.GetResponse();
StreamReader reader = new StreamReader(resp.GetResponseStream());
reader.ReadToEnd();
resp.Close();
FtpWebRequest req2 = (FtpWebRequest)WebRequest.Create(ftp://somehost.com/test/file2.txt); NOTE: Be sure to replace "somehost" in the above code to a valid hostname and file path. I observed that a single TCP command connection (on port 21) to the host was used and two additional connections were used to transfer the contents of the files. Please reply if this is not the case for you. Mike Flasko
FtpWebResponse resp2 = (FtpWebResponse)req2.GetResponse();
StreamReader reader2 = new StreamReader(resp2.GetResponseStream());
reader2.ReadToEnd();
resp2.Close();
Eventhough we reuse connections, please note that no state is maintained across requests. It follows a simple request response model