Our Products:   CompleteFTP  edtFTPnet/Free  edtFTPnet/PRO  edtFTPj/Free  edtFTPj/PRO
0 votes
5.8k views
in Java FTP by (200 points)
I am trying to connect to this ftp site with active connection mode. It works fine when client application started and it started to throw "connect timed out" exception when the ftp site getting busier. I have tried to set ftp timeout property from 1 second to 3 minutes and it did not help. I have also tried to close the connection by call "ftp.quit();" and re-connect the ftp 10 time and all 10 times are failed. If the connection timed out once, it will never be able to reconnect unless I restart the client application. I could understand the "connection timed out" when the ftp site is too busy, but I could not understand why it keep failing after the first timeout exception even the ftp site is not so busy later. I have also tried to run the same client application on different machine when the timeout is happening on the first machine, but the connection was successful.

I fell the the connection is cached some how and did not get closed even ftp.quit() gets called.

I have struggle with this issue for many day, can someone help me out please? Thank you!

4 Answers

0 votes
by (162k points)
Please post a log file set to DEBUG level. It is also worth taking a look at the FTP server logs.
0 votes
by (200 points)
I is impossible to debug FTP server. We have no control over it. We just use it as our EDI communication service.

I set log4j as following, but no debug info from package "com.enterprisedt.net.ftp" get written to ftpClient.log file.

<appender name="FTPClient_FILE" class="org.jboss.logging.appender.DailyRollingFileAppender">
<errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
<param name="File" value="${jboss.server.log.dir}/ftpClient.log"/>
<param name="Append" value="true"/>
<param name="Threshold" value="DEBUG"/>
<param name="DatePattern" value="'.'yyyy-MM-dd"/>

<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d %-5p [%c] (%t) %m%n"/>
</layout>
</appender>

<category name="com.enterprisedt.net.ftp">
<priority value="DEBUG"/>
<appender-ref ref="FTPClient_FILE"/>
</category>


But when I added following, it writes to log file. FileTransferClient is class that I wrote to do all the ftp process like connect, login, quit... using FtpClient class.

<category name="com.FileTransferClient">
<priority value="DEBUG"/>
<appender-ref ref="FTPClient_FILE"/>
</category>

Here is the code in FileTransferClient
FTPClient fTPClient = new FTPClient();
fTPClient.setTimeout(1000);// set to 1 second
int tryCount = 1;
while (true){
try {
log.debug("XXXXXXXX before ftp.connect() - " + tryCount);
fTPClient.connect();
log.debug("XXXXXXXX after ftp.connect() - " + tryCount);
fTPClient.login(user,pass);
log.debug("XXXXXXXX after ftp.login() - " + tryCount);
CONNECTED_COUNT++;
log.debug("CONNECTED_COUNT="+CONNECTED_COUNT);
break;
}catch(Exception e){
if (tryCount < 10){
log.debug("Could not get file, retrying");
ftp.quit();
CONNECTION_COLOSED_COUNT++ ;
log.debug("CONNECTION_COLOSED_COUNT="+CONNECTION_COLOSED_COUNT);
tryCount++;
}else{
log.debug("XXXXXXXX Failed to connect to host - " + host + "\n" + e.getMessage());
e.printStackTrace();
throw new IOException("Failed to connect to host - " + host + "\n" + e.getMessage());
}
}
}
ftp.quit();
CONNECTION_COLOSED_COUNT++ ;
log.debug("CONNECTION_COLOSED_COUNT="+CONNECTION_COLOSED_COUNT);

Anded the log contents when the ftp operation are success. But noting from com.enterprisedt.net.ftp.FTPClient
2008-03-10 11:45:15,389 DEBUG [com.FileTransferClient] (RMI TCP Connection(24)-192.168.1.175) XXXXXXXX before ftp.connect() - 1
2008-03-10 11:46:35,104 DEBUG [com.FileTransferClient] (RMI TCP Connection(24)-192.168.1.175) XXXXXXXX after ftp.connect() - 1
2008-03-10 11:46:55,635 DEBUG [com.FileTransferClient] (RMI TCP Connection(24)-192.168.1.175) XXXXXXXX after ftp.login() - 1
2008-03-10 11:46:55,635 DEBUG [com.FileTransferClient] (RMI TCP Connection(24)-192.168.1.175) CONNECTED_COUNT=1
2008-03-10 11:46:56,338 DEBUG [com.FileTransferClient] (RMI TCP Connection(24)-192.168.1.175) CONNECTION_COLOSED_COUNT=1

Did I do anyting wrong to config the logging for com.enterprisedt.net.ftp.FTPClient?

Thank you for your help!

Deping
0 votes
by (162k points)
Are you setting the timeout in milliseconds?

It should be something like 60,000 at a minimum.

Logger.setLevel(Level.DEBUG);
Logger.addAppender(new FileAppender("mylog.txt"));
0 votes
by (200 points)
Thank you so much for your help!

I finally figured out the problem by set logging to DEBUG in FTPClient code. It is the port number did not get reset to default after a FTPS transaction set port to 990.

Deping

Categories

...