Logged In: NO

an iterative port assignment may work instead of random
number generation. the following code should fix the problem:

1) insert following variables into private member section of
the FTPConnection class:

// count of instances of this object
private static int instance_count = 0;

// list of ports in use
private static ArrayList port_list;

2) insert the following code into the FTPConnection constructor:

if(instance_count == 0)
{
// only create this object one time
port_list = new ArrayList();
}
instance_count ++;

3) replace all the code in the FTPMode.Active case selection
of the GetPortNumber() method:

// sorting ensures best case matching
port_list.Sort();

// search through all possible ports
for(int i=DATA_PORT_RANGE_FROM;i<=DATA_PORT_RANGE_TO;i++)
{
// if the port is not already assigned
if(!port_list.Contains(i))
{
// use it here;
port = i;

// "lock" the port
port_list.Add(i);

// exit the port iteration
break;
}
}

4) finally add the following line at the end of the
FTPMode.Passive case selection of
FTPConnection.GetPortNumber() right before the "break" :

port_list.Add(port);

the static context will ensure that the ports are "unique"
across multiple instances of the FTPConnection object,
however ports will not be "released" by the object until all
instances of the object have been destroyed. This limitation
could be overcome with some more code to manage ports more
effectivly (i.e. putting port as a class variable and
removing it from the port_list when the class's Dispose()
method is called)