FTP send/rename sequence synchronization problem


In my OpenAT application i send several files to a server via FTP and then rename them. Schematically the process is:

foreach file_to_send
	send file
	rename file

Take a look at the “DELAY lines”… Surprisingly i had to implement this delays (Timer based, not blocking of course) so that the ftp client software in the Wavecom module doesn’t trip over itself. I explain this:

the behaviour of the ftp software in the module is "very asynchronous", meaning that after executing primitives like  wip_renameFile / wip_write / wip_close  the sw will signal completion to the handler __well before__ the actual operation (end of filetransfer, rename...) is really completed on the other side (the FTP server). Thus there are big odds that these happens:
a) I send file and then rename it but the file is still open by the FTP server for writing so the rename file cannot execute as the file is blocked.
b) I rename a file (this requires 2 FTP commands to the server: RNFR / RNTO) and i get the WIP_CEV_DONE in the handler but if i start another file transfer before the actual completion with the server, the client software "forgets" to send the RNTO and of course the file doesn't get renamed.

Till now i have found no way to overcome this limitation except but implementing the DELAY’s. I don’t regard this as a very good design specially because the right timeout for the DELAY_A needs to become bigger and bigger when the size of the file increases. Any of you has encountered this problem and has found a better solution?

Thank you and kind regards!