# Active FTP data port problems......

This topic is 4949 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I'm having trouble getting the data port on an ftp connection working. I issue the PORT command and get a succesfull response, but the FTP doesn't seem to attempt to connect to the data port on the client. I know the PORT command is of the format PORT 10,0,0,212,3,4 where the first four are the IP and the last two make up the port (3*256+33). I create a socket and put it into a listening state, but no connection is ever established. Does the FTP server only create the connection once a command requiring the data port is issued? In other words, does the PORT command just tell the server where to make the connection when needed? I thought the PORT command created the data channel. In my code I issue the PORT command then wait for a connection then issue the RETR command; however, I never get a connection. here is the code [C#]
localSocket = new Socket( AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp );
localSocket.Bind( new IPEndPoint( IPAddress.Parse( "10.0.0.212" ), 8*256+29 ) );
localSocket.Listen( 50 );

command = "PORT 10,0,0,212,8,29"+CRLF;
m_cmdSocket.Send( Encoding.ASCII.GetBytes( command ), command.Length, 0 );

while( !localSocket.Connected ) { Console.WriteLine( "waiting..." ); }

I never get past that wait loop. ReadCommandReply() gives me a "PORT command successfull, but I never get a connection. I didn't put this in the .Net forum because this is really a general FTP protocall question although I may have messed up the source code. I'm trying to make sure I understand how PORT works.

##### Share on other sites
You're likely behind some network address translation setup [given an ip like 10.0.0.212, highly likely]. The return connection fails, since 10.0.0.212 is a non-routable IP address.

[edit: that explination wasn't terribly clear... ask any questions about 'why' if anything wasn't very clear...]

##### Share on other sites
10.0.0.212 = client
10.0.0.12 = ftp server

I see what you're saying, but then let me ask you this, the ftp server also resides on the LAN (it's IP address is 10.0.0.12), so I'm not going outside of the LAN for the connection (infact, connecting to 10.0.0.12 for the command stream works fine). I will certainly give your suggestion a try, but what if the ftp is on a LAN not connected to the internet? Then 10.0.0.212 is the only IP address.

##### Share on other sites
turns out, my problem was that i was waiting for the connection right after issuing the PORT command and in actuality, the server does not attempt to connect until after the RETR command (or some command needing the data port) is issued.