in reply to FTP in background

The way which immediately springs to mind (and of course, TMTOWTDI) is to have your script fork into two processes, one of which creates the files, and the other one of which produces them.

You'll need a way of signalling that a particular file is finished to the FTP script, so it doesn't try to upload a half-finished file. Provided that you're not dealing with an NFS filesystem, then flock can work nicely here, resulting in the consumer process efficiently blocking until it has its turn to read the file. There is a potentially rare race condition where the consumer process could lock the file before the producer process has had a chance to lock it first, so it's probably wise for the consumer to never attempt to lock an empty file. This assumes that an empty file is never valid. If an empty file is valid, then you could use file permission bits to indicate when a file is ready for uploading.

You could use shared memory to pass files (or information about files) about, which is a very good solution, as the consumer process can just wait for a message to go ahead with the next file. You could replace shared memory with unix domain sockets here if you felt more comfortable with them.

If fork() gives you the willies, then you could just split your script into two and make sure that one is always started with the other (a small shell script can help here). This means you can't do shared memory, but if you're not comfortable with fork, then the chances are you're not comfortable with shared memory either.

Hope that this helps you get started.

Cheers
Paul