public void testPORT() throws Exception
{
Log log = getLogger(FtpConst.Commands.CMD_PORT);
log.info("Test...");
FtpClientSession client = FtpTestConfig.getTestFtpClient();
client.connect();
assertEquals(FtpConst.Replyes.REPLY_331, client.executeCommand(new CmdUser("admin")));
assertEquals(FtpConst.Replyes.REPLY_230, client.executeCommand(new CmdPass("admin")));
int MIN_PORT_VAL = 9000;
int MAX_PORT_VAL = 10000;
int ports = MAX_PORT_VAL - MIN_PORT_VAL + 1;
Random random = new Random();
String host = "127.0.0.1";
int port = 0;
boolean enableSearch = true;
while (enableSearch)
{
port = MIN_PORT_VAL + random.nextInt(ports);
if (FtpUtils.isPortFree(port))
{
enableSearch = false;
}
}
FtpDataTransiver dataTransiver = new FtpDataTransiverImpl();
dataTransiver.OpenActive(port);
client.setDataTransiver(dataTransiver);
try
{
Thread.sleep(1000);
}
catch (Exception exc)
{
log.info(FtpConst.EXC_MSG + exc.getMessage(), exc);
}
CmdPort cmdPort = new CmdPort(host, port);
assertEquals(FtpConst.Replyes.REPLY_200, client.executeCommand(cmdPort));
boolean connected = false;
for (int i = 0; i < 15; i++)
{
try
{
if (client.getDataTransiver().isConnected())
{
connected = true;
break;
}
Thread.sleep(1000);
}
catch (Exception exc)
{
log.info(FtpConst.EXC_MSG + exc.getMessage(), exc);
}
}
assertEquals(true, connected);
client.getDataTransiver().close();
client.close();
log.info("Complete.");
}