Our application LSIE AI is hosted on RHEL 5.5 AP machine. The application has to FTP some files from a Windows (Server 2003) machine. Our application initiates an active FTP connection to the Windows machine. We are using active mode of ftp. The FTP connection hangs on the Linux side after few minutes and on Windows machine we get the FTP reason codes 425 and 426.

On troubleshooting, we found that FTP transfer fails when Linux tries to reuse a socket. After closing a TCP connection, the Windows server keeps the socket pair (source-ip, dest-ip, source-port, dest-port, protocol) in a TCP TIME_WAIT state for 240 seconds (4 minutes). During this time, if an attempt is made to reuse the socket pair, the connection is declined. So, whenever an FTP client tries to pull multiple files, the first time it tries to reuse a port number within 4 minutes of its earlier usage, the server will fail to make the data connection.
FTP works on our HP-UX machine because HP-UX uses a separate socket for each data connection.

We found that the TCP parameter /proc/sys/net/ipv4/tcp_tw_reuse on the linux box is set to 1. Our understanding is that this parameter will cause Linux to reuse the sockets.
We changed this parameter to 0 without server restart. But this did not fix the FTP problem and Linux is still reusing sockets.

We also tried /proc/sys/net/ipv4/tcp_tw_recycle and tcp_fin_timeout . tcp_fin_timeout property for linux box is 30 sec and Windows is also 30 sec. When we executed the netstat command to monitor the socket status on Linux, it is showing as LISTEN and not TIME-WAIT.

Is it possible to change the /proc/sys/net/ipv4/tcp_tw_reuse file to prevent port reuse completely? Please let me know if there are any other parameters that need to be changed to prevent Linux from reusing sockets during FTP transfer.