The FTPConnection.Read method is cause of exceptionally
bad performance due to poor implementation. Summarizing
the current functionallity: It reads the port for data. If no
data is ready it waits 1 second before reading the port for
data again. If 10 seconds has elapsed without response
from the server it throws an exception. This leads to a
number of performance problems:
1. when using SendCommand method the request will most
likely take 1 second to compute, since data is most likely
not available from the ftp-server only 3-4 instructions later,
thus the client enters a 1 second wait-cycle.
2. To open a connection takes at least 2 seconds since the
Open method use SendCommand to pass the username
and password to the server.
3. Closing the client using a standard ftp-protocol taes at
least 10 seconds. The Close methods uses the
SendCommand to send the non-stadard command "QUIT"
to the server and then waits for a reply. "QUIT" is not part
of the ftp-standard and most servers will not reply to this
message, thus the Read operation times out with an
Exception after 10 seconds.
There are two fixes - The fast, and the correct:
THE FAST:
Let the ftp-client poll the port more frequently for data (say
every 100 ms.) and remove the "QUIT" call to the server,
This reduce an Open and Close operation from 12 seconds
to 300 ms.
THE CORRECT
Busy-waiting is such a bad code-style that it cries to the
heavens. Use the NetworkStream's WaitHandler's WaitOne
method with a suitable timeout (e.g. 10000 ms.). This works
like a charm and makes the FtpClient blitzing fast.
Kind Regards
Sřren Lindstrřm
slind69@hotmail.com
Logged In: NO
Could you give an example of how to implement the correct
solution? I can't even find the networkstream's waithandler.
Logged In: NO
Could you give an example of how to implement the correct
solution? I can't even find the networkstream's waithandler.
Logged In: NO
I dont know how to implement the posted users solution but I
found the waitone thing he/she was talking about in the msdn
files....
I searched for "networkstream waitone" to find that its
refeering to "NetworkStream.BeginRead Method"
The following is the c# example listed in the MSDN document
----------------------------------------------------------
// Check to see if this NetworkStream is readable.
if(myNetworkStream.CanRead){
byte[] myReadBuffer = new byte[1024];
myNetworkStream.BeginRead(myReadBuffer, 0,
myReadBuffer.Length,
new AsyncCallback
(NetworkStream_ASync_Send_Receive.myReadCallBack),
myNetworkStream);
allDone.WaitOne();
}
else{
Console.WriteLine("Sorry. You cannot read from this
NetworkStream.");
}
Logged In: NO
Try this...
I read the RFC for FTP protocol and came up with this
solution that seems to work for me. Absolutely NO delay,
but it will timeout after 10 seconds of no response. (Be
sure to read the comment at the bottom)
de el ka ay wy at verizon dot net
the message");
}
Console.WriteLine((string)messageList[messageList.Count-1]);
Console.WriteLine((string)messageList[messageList.Count-1]);
And then update Dir and XDir to use ReadDirLines() instead
of ReadLines()