I don't think the error is coming from the passive data connections but from new client connections
bind() is not called on new client connections, only on data transfer connections.
and probably related to the SO_REUSEADDR being used on all binds.
SO_REUSEADDR is only enabled if:
1. ReuseSocket is rsTrue.
2. ReuseSocket is rsOSDependent (the default) and GOSType is otUnix (which it is not in your case).
ENABLING SO_REUSEADDR would not be causing your bind errors.
DISABLING it might.
Shouldn't the SO_REUSEADDR just be used on the listening sockets for the server?
In FTP, bind() is used for both listening and connecting sockets. Inbound passive-mode transfer sockets are bound to the passive port range, or to the server's DefaultDataPort if no range is specified. Outbound active-mode transfer sockets are bound to the DefaultDataPort.
It appears that the FTP server applies SO_REUSEADDR to all sockets if the reuseSocket param is set to rsTrue?
Yes (on a per-socket basis).
Maybe I should try setting it to rsFalse and see what happens.
It was not set to rsTrue by default to begin with. So you had to have set it to rsTrue at some point.
The worst that could happen is the main server port might not be available for a few minutes right if I shut it down and then start it back up right away.
Or, the server ports might not be available for a few minutes after each data transfer.
ok, what I did as a test was to disable socket reuse in the ftp server properties and then do this in the bind procedure in IDSocketHandle:
You should not be modifying Indy's source code like that. TIdFTPServer has published OnBeforeBind and OnDataPortBeforeBind events. The first event is for the main listening sockets that clients connect to for commands, the second event is for the data transfer sockets.