B
Brock Heinz
Hi All,
I have a pretty interesting problem. First I'll explain my scenario,
and then I'll pose my question.
I've written a TimerTask that regularly checks for a file on my FTP
server. In each cycle the task must determine 1. If the file exists
and then 2. if the file isn't currently being written to by an FTP
process. I want to ensure that I only act upon files that have been
fully transfered to my FTP server.
The first part is simple - I can easily determine if the file is
present. The second part though is causing me headaches. How can I
know if the FTP process is done? Does anyone have any experience with
this? Is it very platform / process (FTP in this case) dependent?
Here is what I was thinking, but my tests are not turning anything
positive up...
private boolean fileAvailable(File file) {
//ensure that the file exists
if (file.exists()) {
FileChannel fc = new RandomAccessFile(file, "rw").getChannel();
//attempt a lock
try {
//this is an exclusive lock
fc.lock();
} catch (Throwable t) {
//ftp still has file locked...
return false;
}
//able to lock file - release
fc.close();
return true;
} else {
//no file
return false;
}
}
Thanks,
Brock
I have a pretty interesting problem. First I'll explain my scenario,
and then I'll pose my question.
I've written a TimerTask that regularly checks for a file on my FTP
server. In each cycle the task must determine 1. If the file exists
and then 2. if the file isn't currently being written to by an FTP
process. I want to ensure that I only act upon files that have been
fully transfered to my FTP server.
The first part is simple - I can easily determine if the file is
present. The second part though is causing me headaches. How can I
know if the FTP process is done? Does anyone have any experience with
this? Is it very platform / process (FTP in this case) dependent?
Here is what I was thinking, but my tests are not turning anything
positive up...
private boolean fileAvailable(File file) {
//ensure that the file exists
if (file.exists()) {
FileChannel fc = new RandomAccessFile(file, "rw").getChannel();
//attempt a lock
try {
//this is an exclusive lock
fc.lock();
} catch (Throwable t) {
//ftp still has file locked...
return false;
}
//able to lock file - release
fc.close();
return true;
} else {
//no file
return false;
}
}
Thanks,
Brock