Our Products:   CompleteFTP  edtFTPnet/Free  edtFTPnet/PRO  edtFTPj/Free  edtFTPj/PRO
0 votes
11.7k views
in .NET FTP by (240 points)
Active FTP can fail during the file transfer when the active IP address has been specifically set.

This happens because the data socket is bound to the IP address of the control socket and not the IP address specified when the active IP address was set.

The problem is in the NewActiveDataSocket function of the FTPControlSocket class. It currently contains:

log.Debug("NewActiveDataSocket(" + port + ")");
// choose specified port
IPEndPoint endPoint = new IPEndPoint(((IPEndPoint)controlSock.LocalEndPoint).Address, port);
sock.Bind(endPoint);

Since there is no guarantee that the control socket was created with the same IP address specified when the active IP address set, the data transfer can fail because the PORT command tells the server the wrong IP address to connect to.

A much better implementation that fixes the problem is:

log.Debug("NewActiveDataSocket(" + port + ")");
// choose specified port
IPEndPoint endPoint;
if (activeIPAddress != null)
{
  endPoint = new IPEndPoint(activeIPAddress, port);
}
else
{
  endPoint = new IPEndPoint(((IPEndPoint)controlSock.LocalEndPoint).Address, port);
}
sock.Bind(endPoint);     

An even better implementation would force the control socket to bind to the IP specified for the active IP address instead of allowing the OS to decide.

And as we all know, letting Windows decide anything is just a bad idea :-)

12 Answers

0 votes
by (162k points)
Ah ok. As noted above, the main issue with this is that it is quite possible that the ActiveIPAddress isn't actually on the local machine, and so bind may fail.

I think we'll add this fix ourselves, but do an additional check to make sure the ActiveIPAddress is indeed a local interface. If it isn't, then you should bind on the control socket's address.
0 votes
by (220 points)
I understand the issue associated with this fix, but it worked for me. Maybe I'll revisit and implement the alternative you recommended two years ago. Or just wait until you folks put it in. :D

Thanks.

Categories

...