Hello,
I currently have a project that will require me to exchange files via FTP. I have to run both a client and server, and both will need to utilize active FTP. I have read up on FTP, and believe I have a fairly good understanding of active vs passive. It would appear that my client will have to issue a PORT command, informing the server as to which data port to connect to. From what I have read, typically the data port on the client is the command port +1. How would I find what port a connection is open? What I have is:
private static Socket CommandSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); private static Socket DataSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); private static int DataPort; public static void SendFile() { string RemoteHost = "192.168.1.44"; int RemotePort = 21; IPAddress RemoteServerIP = IPAddress.Parse(RemoteHost); IPEndPoint RemoteServerCmdEP = new IPEndPoint(RemoteServerIP, RemotePort); try { Debug.Print("Starting Connection"); CommandSocket.Connect(RemoteServerCmdEP); Debug.Print("Connected"); }
I know that I am connecting to port 21 on the remote end, but how can I see which port on the ND is utilized to make that connection? I assume that is will be somewhere in CommandSocket.LocalEndpoint, but I cannot seem to find it.
Thanks,
Brandon