A: 

FTP protocol has two channels - the control channel on which you send commands, and data channel on which you send/receive data.

Also, you will have to parse the response of the server to see where the end of stream lies.

Get a tracelog (see http://ferozedaud.blogspot.com/2009/08/tracing-with-systemnet.html) and put it on pastebin, that will help show what the problem is.

feroze
A: 
Thanks for your advice. Here is my tracelog:
------------------------------------------------------------------
System.Net.Sockets Verbose: 0 : [3364] Socket#61940669::Socket(InterNetwork#2)
System.Net.Sockets Verbose: 0 : [3364] Exiting Socket#61940669::Socket() 
System.Net.Sockets Verbose: 0 : [3364] Socket#61940669::BeginConnect(127.0.0.1)
System.Net.Sockets Verbose: 0 : [3364] DNS::UnsafeBeginGetHostAddresses(127.0.0.1)
System.Net.Sockets Verbose: 0 : [3364] Exiting DNS::UnsafeBeginGetHostAddresses()   -> Dns+ResolveAsyncResult#15193904
System.Net.Sockets Verbose: 0 : [3364] DNS::EndGetHostAddresses(Dns+ResolveAsyncResult#15193904)
System.Net.Sockets Verbose: 0 : [3364] Exiting DNS::EndGetHostAddresses()   -> IPHostEntry#6303833
System.Net.Sockets Verbose: 0 : [3364] Exiting Socket#61940669::BeginConnect()  -> Socket+MultipleAddressConnectAsyncResult#40452378
System.Net.Sockets Verbose: 0 : [2520] Socket#61940669::EndConnect(ConnectAsyncResult#42931033)
System.Net.Sockets Verbose: 0 : [2520] Exiting Socket#61940669::EndConnect() 
System.Net.Sockets Verbose: 0 : [2520] Socket#61940669::EndConnect(Socket+MultipleAddressConnectAsyncResult#40452378)
System.Net.Sockets Verbose: 0 : [2520] Exiting Socket#61940669::EndConnect() 
System.Net.Sockets Verbose: 0 : [3364] Socket#61940669::BeginReceive()
System.Net.Sockets Verbose: 0 : [2520] Data from Socket#61940669::PostCompletion
System.Net.Sockets Verbose: 0 : [3364] Exiting Socket#61940669::BeginReceive()  -> OverlappedAsyncResult#36009496
System.Net.Sockets Verbose: 0 : [2520] 00000000 : 32 32 30 20 57 65 6C 63-6F 6D 65 20 74 6F 20 42 : 220 Welcome to B
System.Net.Sockets Verbose: 0 : [2520] 00000010 : 61 62 79 20 46 54 50 20-53 65 72 76 65 72 0D 0A : aby FTP Server..
System.Net.Sockets Verbose: 0 : [2520] Socket#61940669::EndReceive(OverlappedAsyncResult#36009496)
System.Net.Sockets Verbose: 0 : [2520] Exiting Socket#61940669::EndReceive()    -> 32#32
System.Net.Sockets Verbose: 0 : [2520] Socket#61940669::BeginReceive()
System.Net.Sockets Verbose: 0 : [2520] Exiting Socket#61940669::BeginReceive()  -> OverlappedAsyncResult#39053774
System.Net.Sockets Verbose: 0 : [3364] Socket#61940669::BeginSend()
System.Net.Sockets Verbose: 0 : [2520] Data from Socket#61940669::PostCompletion
System.Net.Sockets Verbose: 0 : [2520] 00000000 : 33 33 31 20 55 73 65 72-20 6E 61 6D 65 20 6F 6B : 331 User name ok
System.Net.Sockets Verbose: 0 : [2520] 00000010 : 2C 20 6E 65 65 64 20 70-61 73 73 77 6F 72 64 2E : , need password.
System.Net.Sockets Verbose: 0 : [2520] 00000020 : 0D 0A                                           : ..
System.Net.Sockets Verbose: 0 : [2520] Socket#61940669::EndReceive(OverlappedAsyncResult#39053774)
System.Net.Sockets Verbose: 0 : [2520] Exiting Socket#61940669::EndReceive()    -> 34#34
System.Net.Sockets Verbose: 0 : [3364] Exiting Socket#61940669::BeginSend()     -> OverlappedAsyncResult#19634871
System.Net.Sockets Verbose: 0 : [2520] Socket#61940669::BeginReceive()
System.Net.Sockets Verbose: 0 : [2520] Exiting Socket#61940669::BeginReceive()  -> OverlappedAsyncResult#55467396
System.Net.Sockets Verbose: 0 : [2520] Data from Socket#61940669::PostCompletion
System.Net.Sockets Verbose: 0 : [2520] 00000000 : 55 53 45 52 20 61 6E 6F-6E 79 6D 6F 75 73 0D 0A : USER anonymous..
System.Net.Sockets Verbose: 0 : [2520] Socket#61940669::EndSend(OverlappedAsyncResult#19634871)
System.Net.Sockets Verbose: 0 : [2520] Exiting Socket#61940669::EndSend()   -> 16#16
System.Net.Sockets Verbose: 0 : [3364] Socket#61940669::BeginReceive()
System.Net.Sockets Verbose: 0 : [3364] Exiting Socket#61940669::BeginReceive()  -> OverlappedAsyncResult#22584602
System.Net.Sockets Verbose: 0 : [3364] Socket#61940669::Shutdown(Both#2)
System.Net.Sockets Verbose: 0 : [2520] Data from Socket#61940669::PostCompletion
System.Net.Sockets Verbose: 0 : [2520] 00000000 :                                                 : 
System.Net.Sockets Verbose: 0 : [2520] Socket#61940669::EndReceive(OverlappedAsyncResult#55467396)
System.Net.Sockets Verbose: 0 : [2520] Exiting Socket#61940669::EndReceive()    -> 0#0
System.Net.Sockets Verbose: 0 : [2520] Data from Socket#61940669::PostCompletion
System.Net.Sockets Verbose: 0 : [2520] 00000000 :                                                 : 
System.Net.Sockets Verbose: 0 : [3364] Exiting Socket#61940669::Shutdown() 
System.Net.Sockets Verbose: 0 : [3364] Socket#61940669::Close()
System.Net.Sockets Verbose: 0 : [3364] Socket#61940669::Dispose()
System.Net.Sockets Verbose: 0 : [3364] Exiting Socket#61940669::Close() 
System.Net.Sockets Verbose: 0 : [2520] Socket#61940669::EndReceive(OverlappedAsyncResult#22584602)
-----------------------------------------------------------
Confusing these things:
1. Answer string '331 User name ok, need password'
goes earlier than my command 'USER anonymous'.
2. Some 'Socket#61940669::BeginReceive()' events overlapped with
'Socket#61940669::BeginSend()' events (without corresponding EndXXX)
and vice versa.
In my understanding, after 'BeginReceive' event there must be 
'EndReceive' event, not 'BeginSend'.
Or am i wrong to interpret tracelog?
Sergey
A: 
Sergey
-1, This is NOT the fix you're looking for, move along now. You can't rely on that behaviour. TCP is a stream of bytes, each read can return anything from 1 to the size of your buffer. TCP does not respect your idea of message boundaries. TCP is a stream of bytes. That code is broken as it assumes you will get a complete response in one read. You should ALWAYS code as if you will always get a single byte returned by EVERY read you issue.
Len Holgate