Reputation: 141
I'm using Apache ftpserver (Java). I need to have a nofication in my program when a file is uploaded through the ftp. It seems to be possible but i can't find the way how to do it.
Any solutions out there?
mina.apache.org/ftpserver
Upvotes: 1
Views: 1773
Reputation: 765
You can get all notifications using ftplet. Check this out ... http://apilevel.wordpress.com/2011/05/12/ftplet-servlet-for-apache-ftpserver/
Upvotes: 3
Reputation: 33534
I am assuming that, you have a desktop program, which is running on the ftpserver itself.. So as soon as any file is uploaded to the same ftpserver, your program must inform it...Right.!!
Lets see....
I am sure you have created a directory in the ftp server where the files will be uploaded.
Make this program of your which is running on the same server to keep looking at the total nos of files in that folder/directory say for every 2mins or as per your requirement..Once the program notices that the nos of files have increased then i will raise an event of some kind in the program to inform u.
How to do it...
Create a Separate thread to keep looping the directory for any change in the nos of files. Do Not make the Event Dispatcher thread to do it..else your GUI will be Hanged.
Try the logic below..
private static int max = 0; // i am assuming the folder is Empty.
while(true) {
File f = new File("path_of_files_on_ftp_server");
File[] farr = f.listFiles();
if ( farr.length > max ){
// There has been an upload......
// Raise the alarm here, by doing some event....
max = farr.length ;
}
else {
continue;
}
}
Upvotes: 1