Linux – Upload files from vsftpd ftp client in /tmp and once they are uploaded, move them to original folder

centos6.5ftplinuxunixupload

I'm having issues with my application. The scenario is that, there is a php cron which is running every 1 minute and it processes the uploads folder, wherein, files are uploaded via ftp server(vsftpd). If the server is uploading a file which is 1GB, the php cron will process the files, even if it is not uploaded completely. I can't change the cron timing, but I want to know if, whether vsftpd has any function, by which can upload the file in /tmp and then move to original folder once the upload is complete?

Best Answer

No, it does not have this function built in.
There are solutions to this though.

The probably best is, to tell the uploading program to upload it with a different name, e.g. file-whatever.txt.incomplete and once the upload is completed rename it it the normal name.
The advantage is:
The rename is fast (since the file is on the same filesystem).
If a upload doesn't finish correctly, it doesn't get renamed.
Disadvantage of course, you need changes in both the uploading process and the PHP cronjob (to ignore *.incomplete files).

The other solution is to upload it to a different folder like you suggested and watch it with something like incron.
With that you can watch a folder and move completed files to a different folder.
Disadvantage: if a upload fails halfway through it will still get moved and possibly processed.

Related Topic