Truncated files on Red Hat server after FTP uploads
Q I am having some trouble with an updated Red Hat server at work. We have an applet that makes an FTP connection to the server, and users can upload files. This all works fine. The problem lies with a script that runs on the server to look for changes in the modification date of the folder that they are loaded into. When the date changes it processes the file. This worked fine on the old server, but on the new server it appears that while the transfer is in process the folder modification date is being changed. This means that we are getting truncated files, because the process starts before the transfer is complete. Is there any way to set how folder modification dates are created? Is it an FTP issue or an OS issue? The server is RHEL ES 4, the old server was RHEL ES 2.
A Is your script looking at the file modification dates manually? The problem is that the folder is modified twice: once when the new file is opened at the start of the upload and again when it is closed on completion. I had to set something like this up recently and found the best approach is to use the Fam (File Alteration Monitor) service, which is able to distinguish between these events. You need to install Fam and ensure that the famd service is run at startup. Then you need a program that will ask the server to watch for changes to your files or directories and take the appropriate action when informed of them. I found the fileschanged program ideal for this if all you need to do is run a script. You can get fileschanged from http://fileschanged.sourceforge.net, and run it like this:
fileschanged --show changed --exec /usr/local/bin/ourscript /var/ftp/somedir/
The --show option tells fileschanged to listen only for changes to files in the directory, skipping the initial notification when the file is created (fileschanged can also watch for files being deleted or executed). When it receives a notification, it runs the script with two arguments. The first is a single letter indicating the type of file change: 'M' for modified. The second argument is the name of the file. With this information, your script knows the name of the file that was uploaded and can do whatever you want. You may also find it useful to add a --timeout option to increase the delay in notification of changes to a file.
- Files disappearing on Apache Tomcat server using RAID
- Analysing web server log files
- Sendmail server load spikes
- Map Windows Storage Server on Linux
- Best server hardware for Linux compatibility?