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 :-)