public delegate void DirListDelegate(object sender, ArrayList items);public event DirListDelegate OnDirListComplete;
private void OnDataReceived(IAsyncResult asyn) { int bytes = dataSocket.EndReceive(asyn); bldBuffer.Append(Encoding.ASCII.GetString(buffer, 0, bytes)); if(bytes < buffer.Length) { dataSocket.Close(); // Trimmed code to process data into "itemsList" OnDirListComplete(this, itemsList); } else { WaitForData(); }}private void WaitForData() { dataSocket.BeginReceive(buffer, 0, buffer.Length, SocketFlags.None, new AsyncCallback(OnDataReceived), null);}public void ListDir() { dataSocket = openSocket(); //trimmed code to make server initiate transfer ("LIST -al") bldBuffer.Remove(0, bldBuffer.Length); WaitForData();}