Our Products:   CompleteFTP  edtFTPnet/Free  edtFTPnet/PRO  edtFTPj/Free  edtFTPj/PRO
0 votes
5.2k views
in Java FTP by (120 points)
Hi,

I'm instantiating a new FTPClient within a TimerTask run() method. The Timer using this TimerTask is scheduled for fixed-rate execution every minute. This runs glitch-free, connecting to the site and downloading any new files, usually for 24-48 hours - and then just hangs on instantiation of the client. No response is received from the server at all - it's as if the FTPClient is forever awaiting a response that never comes. At these times it is still possible to access the ftp server using a normal command line client. Any ideas what the problem may be?

Regards,

fpr

3 Answers

0 votes
by (162k points)
You'll need to post some code ... and the debug log would be helpful.

Hi,

I'm instantiating a new FTPClient within a TimerTask run() method. The Timer using this TimerTask is scheduled for fixed-rate execution every minute. This runs glitch-free, connecting to the site and downloading any new files, usually for 24-48 hours - and then just hangs on instantiation of the client. No response is received from the server at all - it's as if the FTPClient is forever awaiting a response that never comes. At these times it is still possible to access the ftp server using a normal command line client. Any ideas what the problem may be?

Regards,

fpr
0 votes
by
Many thanks for the quick response. Please find the run method from the TimerTask below.

The debug log currently goes to the console so I can't include that - suffice to say there's nothing in it after my own "Connecting to ..." logging message. What I usually get immediately after the "Connecting to ..." message on a successful run is obviously a "DEBUG ... 220 ... Ready" message. By the way, my "Task complete" logging message from the last successful run before the hung run was issued 59 seconds before the final "Connecting to ..." message. Hope that's clear!

Regards and thanks,

fpr

public void run() {

String filename;
long size1, size2;
GregorianCalendar D1=new GregorianCalendar(), D2;
File lock;

lock=new File(this.lockfile);
try {
if (!lock.createNewFile()) {
if (this.loggerset) {this.logger.log(Level.INFO, "Lockfile "+this.lockfile+" already exists");}
}
else {
try {
if (this.loggerset) {
this.logger.log(Level.INFO, "Connecting to "+this.ftpsite);
}
this.ftp=new FTPClient(this.ftpsite);
this.ftp.setTimeout(this.timeout);
this.ftp.login(this.username, this.password);
this.ftp.setType(FTPTransferType.BINARY);
String [] list=this.ftp.dir("");
if (list.length!=0) {
if (this.loggerset) {
this.logger.log(Level.INFO, "Server "+this.ftpsite+" contains "+list.length+" files");
}
}
this.file_list=new String[list.length];
for (int i=0;i<list.length;i++) {
this.remote_file=list[i];
this.local_file=outdir+System.getProperty("file.separator")+list[i];
this.file_list[i]=this.local_file;
size1=1;size2=0;
while (size1!=size2) {
size1=this.ftp.size(this.remote_file);
D1=new GregorianCalendar();D2=new GregorianCalendar();D2.add(D2.SECOND,2);
while (D1.before(D2)) {
D1=new GregorianCalendar();
}
size2=this.ftp.size(this.remote_file);
}
if (this.loggerset) {this.logger.log(Level.INFO, "Transferring remote file "+this.remote_file+" to "+this.local_file);}
this.ftp.get(this.local_file, this.remote_file);
//this.ftp.delete(this.remote_file);
this.fileProcess(this.local_file);
}
this.listProcess(this.file_list);
}
catch (Exception e) {
SimpleDateFormat sdf=new SimpleDateFormat("HH:mm zzz, dd MMMMMMMMM yyyy");
if (this.loggerset) {this.logger.log(Level.WARNING, "ftp error occurred during connection to "+this.ftpsite+" at "+sdf.format(new Date()), e);}
}
finally {this.ftp.quit();}
}
}
catch (Exception e) {
if (this.loggerset) {
this.logger.log(Level.WARNING, "Could not create lockfile "+this.lockfile);
}
}
if (!lock.delete()) {
if (this.loggerset) {
this.logger.log(Level.WARNING, "Could not delete lockfile "+this.lockfile);
}
}
lock.deleteOnExit();
this.logger.log(Level.INFO, "Task complete");
}
0 votes
by (162k points)
Is it possible that every minute is too frequent? It could be that you are running out of sockets on the client or something like that. The code looks ok.
If possible, try every 5 minutes, or even every 90s.

Many thanks for the quick response. Please find the run method from the TimerTask below.

Categories

...