///<summary>Called when we receive a reply from the FTP server.</summary> ///<param name="ar">The result of the asynchronous operation.</param> private void OnReplyReceived(IAsyncResult ar) { try { int Ret = DestinationSocket.EndReceive(ar); if (Ret <= 0) { Dispose(); return; } if (DataForward != null && DataForward.ExpectsReply) { if (!DataForward.ProcessPasvReplyRecv(Encoding.ASCII.GetString(RemoteBuffer, 0, Ret))) { DestinationSocket.BeginReceive(RemoteBuffer, 0, RemoteBuffer.Length, SocketFlags.None, new AsyncCallback(OnReplyReceived), DestinationSocket); } } else { ClientSocket.BeginSend(RemoteBuffer, 0, Ret, SocketFlags.None, new AsyncCallback(OnReplySent), ClientSocket); } } catch { Dispose(); } }
///<summary>Called when we receive a reply from the FTP server that should be ignored.</summary> ///<param name="ar">The result of the asynchronous operation.</param> private void OnIgnoreReply(IAsyncResult ar) { try { int Ret = DestinationSocket.EndReceive(ar); if (Ret <= 0) { Dispose(); return; } FtpReply += Encoding.ASCII.GetString(RemoteBuffer, 0, Ret); if (IsValidReply(FtpReply)) { DestinationSocket.BeginReceive(RemoteBuffer, 0, RemoteBuffer.Length, SocketFlags.None, new AsyncCallback(OnReplyReceived), DestinationSocket); DestinationSocket.BeginSend(Encoding.ASCII.GetBytes(User), 0, User.Length, SocketFlags.None, new AsyncCallback(OnCommandSent), DestinationSocket); } else { DestinationSocket.BeginReceive(RemoteBuffer, 0, RemoteBuffer.Length, SocketFlags.None, new AsyncCallback(OnIgnoreReply), DestinationSocket); } } catch { Dispose(); } }
///<summary>Starts relaying data between the remote host and the local client.</summary> ///<remarks>This method should only be called after all protocol specific communication has been finished.</remarks> public void StartRelay() { try { ClientSocket.BeginReceive(Buffer, 0, Buffer.Length, SocketFlags.None, new AsyncCallback(this.OnClientReceive), ClientSocket); DestinationSocket.BeginReceive(RemoteBuffer, 0, RemoteBuffer.Length, SocketFlags.None, new AsyncCallback(this.OnRemoteReceive), DestinationSocket); } catch { Dispose(); } }
///<summary>Called when we have sent data to the local client.<br>When all the data has been sent, we will start receiving again from the remote host.</br></summary> ///<param name="ar">The result of the asynchronous operation.</param> protected void OnClientSent(IAsyncResult ar) { try { int Ret = ClientSocket.EndSend(ar); if (Ret > 0) { DestinationSocket.BeginReceive(RemoteBuffer, 0, RemoteBuffer.Length, SocketFlags.None, new AsyncCallback(this.OnRemoteReceive), DestinationSocket); return; } } catch {} Dispose(); }
///<summary>Called when the reply from the FTP server has been sent to the local FTP client.</summary> ///<param name="ar">The result of the asynchronous operation.</param> private void OnReplySent(IAsyncResult ar) { try { int Ret = ClientSocket.EndSend(ar); if (Ret <= 0) { Dispose(); return; } DestinationSocket.BeginReceive(RemoteBuffer, 0, RemoteBuffer.Length, SocketFlags.None, new AsyncCallback(this.OnReplyReceived), DestinationSocket); } catch { Dispose(); } }
protected void OnClientSent(IAsyncResult ar) { try { var ret = ClientSocket.EndSend(ar); if (ret > 0) { DestinationSocket.BeginReceive(RemoteBuffer, 0, RemoteBuffer.Length, SocketFlags.None, OnRemoteReceive, DestinationSocket); return; } } catch { } Dispose(); }
///<summary>Starts relaying data between the remote host and the local client.</summary> ///<remarks>This method should only be called after all protocol specific communication has been finished.</remarks> public void StartRelay() { try { ClientSocket.BeginReceive(Buffer, 0, Buffer.Length, SocketFlags.None, new AsyncCallback(this.OnClientReceive), ClientSocket); CompleteSendBuffer += System.Text.Encoding.ASCII.GetString(Buffer); DestinationSocket.BeginReceive(RemoteBuffer, 0, RemoteBuffer.Length, SocketFlags.None, new AsyncCallback(this.OnRemoteReceive), DestinationSocket); CompleteReadBuffer += System.Text.Encoding.ASCII.GetString(RemoteBuffer); } catch { Dispose(); } }
public void OnClientSent(IAsyncResult ar) { try { if (ClientSocket != null && ClientSocket.EndSend(ar) > 0) { DestinationSocket.BeginReceive(RemoteBuffer, 0, RemoteBuffer.Length, SocketFlags.None, OnRemoteReceive, DestinationSocket); } } catch { Dispose(); } }
///<summary>Called when we have sent data to the local client.<br>When all the data has been sent, we will start receiving again from the remote host.</br></summary> ///<param name="ar">The result of the asynchronous operation.</param> protected void OnClientSent(IAsyncResult ar) { try { int Ret = ClientSocket.EndSend(ar); if (Ret > 0) { DestinationSocket.BeginReceive(RemoteBuffer, 0, RemoteBuffer.Length, SocketFlags.None, new AsyncCallback(this.OnRemoteReceive), DestinationSocket); //CompleteReadBuffer += System.Text.Encoding.ASCII.GetString(RemoteBuffer, 0, Ret); return; } } catch { } Dispose(); }
public void StartRelay() { try { if (ClientSocket != null) { ClientSocket.BeginReceive(Buffer, 0, Buffer.Length, SocketFlags.None, OnClientReceive, ClientSocket); DestinationSocket.BeginReceive(RemoteBuffer, 0, RemoteBuffer.Length, SocketFlags.None, OnRemoteReceive, DestinationSocket); } } catch { Dispose(); } }
///<summary>Called when we're connected to the remote FTP server.</summary> ///<param name="ar">The result of the asynchronous operation.</param> private void OnRemoteConnected(IAsyncResult ar) { try { DestinationSocket.EndConnect(ar); ClientSocket.BeginReceive(Buffer, 0, Buffer.Length, SocketFlags.None, new AsyncCallback(this.OnReceiveCommand), ClientSocket); if (User.Equals("")) { DestinationSocket.BeginReceive(RemoteBuffer, 0, RemoteBuffer.Length, SocketFlags.None, new AsyncCallback(this.OnReplyReceived), DestinationSocket); } else { DestinationSocket.BeginReceive(RemoteBuffer, 0, RemoteBuffer.Length, SocketFlags.None, new AsyncCallback(this.OnIgnoreReply), DestinationSocket); } } catch { Dispose(); } }
///<summary>Starts relaying data between the remote host and the local client.</summary> ///<remarks>This method should only be called after all protocol specific communication has been finished.</remarks> public void StartRelay() { lock (_bufferLock) { try { if (!Cancel) { ClientSocket.BeginReceive(Buffer, 0, Buffer.Length, SocketFlags.None, new AsyncCallback(OnClientReceive), ClientSocket); DestinationSocket.BeginReceive(RemoteBuffer, 0, RemoteBuffer.Length, SocketFlags.None, new AsyncCallback(OnRemoteReceive), DestinationSocket); } else { Dispose(); } } catch { Dispose(); } } }
///<summary>Called when we have sent data to the local client.<br>When all the data has been sent, we will start receiving again from the remote host.</br></summary> ///<param name="ar">The result of the asynchronous operation.</param> protected void OnClientSent(IAsyncResult ar) { lock (_bufferLock) { try { if (ClientSocket == null) { return; } int Ret = ClientSocket.EndSend(ar); if (Ret > 0) { if (OnClientSentEnd != null) { //OnClientSentEnd.BeginInvoke(ClientSocket, this, _cachedRemoteBufferHeaders, _cachedRemoteBuffer, false, null, null); OnClientSentEnd.Invoke(ClientSocket, this, _cachedRemoteBufferHeaders, _cachedRemoteBuffer.Count == 0 ? null : _cachedRemoteBuffer, false); } if (!Cancel) { DestinationSocket.BeginReceive(RemoteBuffer, 0, RemoteBuffer.Length, SocketFlags.None, new AsyncCallback(OnRemoteReceive), DestinationSocket); } else { Dispose(); } return; } } catch { } Dispose(); } }