private bool ProcessCommand(string Command) { try { int Ret = Command.IndexOf(' '); if (Ret < 0) { Ret = Command.Length; } switch (Command.Substring(0, Ret).ToUpper().Trim()) { case "OPEN": ConnectTo(ParseIPPort(Command.Substring(Ret + 1))); break; case "USER": Ret = Command.IndexOf('@'); if (Ret < 0) { return(true); } else { User = Command.Substring(0, Ret).Trim() + "\r\n"; ConnectTo(ParseIPPort(Command.Substring(Ret + 1))); } break; case "PORT": ProcessPortCommand(Command.Substring(5).Trim()); break; case "PASV": DataForward = new FtpDataConnection(); DataForward.ProcessPasv(this); return(true); default: return(true); } return(false); } catch { Dispose(); return(false); } }
private void ProcessPortCommand(string Input) { try { string[] Parts = Input.Split(','); if (Parts.Length == 6) { DataForward = new FtpDataConnection(); string Reply = DataForward.ProcessPort(new IPEndPoint(IPAddress.Parse(String.Join(".", Parts, 0, 4)), int.Parse(Parts[4]) * 256 + int.Parse(Parts[5]))); DestinationSocket.BeginSend(Encoding.ASCII.GetBytes(Reply), 0, Reply.Length, SocketFlags.None, new AsyncCallback(this.OnCommandSent), DestinationSocket); } } catch { Dispose(); } }