private void OpenActiveDataConnection() { Socket dataSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); IPHostEntry localhostEntry = Dns.GetHostByName(Dns.GetHostName()); IPEndPoint listener = new IPEndPoint(localhostEntry.AddressList[0], 0); dataSocket.Bind(listener); dataSocket.Listen(5); IPEndPoint localEP = (IPEndPoint)dataSocket.LocalEndPoint; UInt32 localEPAddress = (UInt32)localEP.Address.Address; string local = FormatAddress(localEPAddress, localEP.Port); CommandResponse response = SendCommand("PORT", local); dataStream = new FtpDataStream(dataSocket); }
private void OpenPassiveDataConnection() { CommandResponse response = SendCommand("PASV", null); if (response.Status != 227) { throw new ApplicationException("Couldn't open passive data connection, no DataConnection IP was given"); } // TODO Use this IP instead of the same as the communication ip string ip = GetIP(response); int port = GetPort(response); Socket dataSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); IPHostEntry serverHostEntry = Dns.GetHostByName(uri.Host); IPEndPoint serverEndPoint = new IPEndPoint(serverHostEntry.AddressList[0], port); dataSocket.Connect(serverEndPoint); dataStream = new FtpDataStream(dataSocket); }
internal FtpWebResponse(FtpDataStream stream) { dataStream = stream; }