private async void AsyncControlReader(System.IO.StreamReader reader, FTPControlChannelReceiver receiver) { do { string readLine = await reader.ReadLineAsync(); receiver.Push(readLine); } while (this.controlConnection.Connected); }
public virtual void Close() { if (this.controlReader != null) { // this.controlReader.Close(); this.controlReader.Dispose(); this.controlReader = null; } if (this.controlWriter != null) { // this.controlWriter.Close(); this.controlWriter.Dispose(); this.controlWriter = null; } if (this.controlChannelReceiver != null) { this.controlChannelReceiver.Clear(); this.controlChannelReceiver = null; } if (this.controlConnection != null) { try { this.controlConnection.GetStream().Dispose(); this.controlConnection.Close(); this.controlConnection.Dispose(); } catch (System.InvalidOperationException) { } this.controlConnection = null; } }
public void Open(System.Net.IPAddress Address, int Port) { if (this.p_IsOpened) { throw new FTPClientException("The connection is already opened."); } this.p_Address = Address; this.p_Port = Port; try { this.controlConnection = new System.Net.Sockets.TcpClient(this.p_Address.ToString(), this.p_Port); } catch (System.Net.Sockets.SocketException e) { throw new FTPClientException("Error connecting to FTP server.", e); } this.controlWriter = this.OpenWriter(this.controlConnection); this.controlChannelReceiver = new FTPControlChannelReceiver(); this.controlChannelReceiver.ResponseReceived += this.ControlChannelResponseReceived; this.controlChannelReceiver.ResponseCompleted += this.ControlChannelResponseCompleted; this.controlReader = this.OpenReader(this.controlConnection); this.AsyncControlReader(this.controlReader, this.controlChannelReceiver); }