FtpWebRequest connection

Is the FtpWebRequest connection persistent, so i can send more than a command?

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

[230 byte] By [luca82] at [2008-2-1]
# 1
Hi Luca82,

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);
FtpWebResponse resp2 = (FtpWebResponse)req2.GetResponse();
StreamReader reader2 = new StreamReader(resp2.GetResponseStream());
reader2.ReadToEnd();
resp2.Close();

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

MikeFlasko at 2007-9-9 > top of Msdn Tech,.NET Development,.NET Framework Networking and Communication...
# 2
We have the concept of connection management for WebRequest class.
For more information please visit http://blogs.msdn.com/adarshk/search.aspx?q=servicepoint&p=1
FtpWebRequest extends from WebRequest and hence takes advantage of the connection management functionality.

Eventhough we reuse connections, please note that no state is maintained across requests. It follows a simple request response model

Malar at 2007-9-9 > top of Msdn Tech,.NET Development,.NET Framework Networking and Communication...
# 3
thank you very mich for your answers guys :)
luca82 at 2007-9-9 > top of Msdn Tech,.NET Development,.NET Framework Networking and Communication...

.NET Development

Site Classified