Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Here's a doozy - wait for an ftp transfer to complete 2

Status
Not open for further replies.

ITfromZX81

Programmer
May 18, 2004
151
CA
Hey there,

I have a weird issue.

I am writing a program that waits until a file exists in a folder before opening it in another external program.

This part works fine - it will check for FileExists and waits until the file is there.

However, the file is transferred to that folder via FTP. The problem is that the file appears in the folder before it is complete - it starts at 0 bytes and then slowly goes up(I tested this by transferring and watching the file progress by pressing F5 to refresh the folder in windows).

My program, though, sees the file and opens it immediately -it has no way of knowing that the file isn't complete yet - the result is that the external program opens a blank file. If I wait until the file is sent and then start my program it then works fine, but I'm trying to automate a process so that isn't a solution.

I'm stumped - other than setting an arbitrary wait time before trying to open the file I'm not really sure how to get around this. I'd rather not get into writing my own ftp server if I can help it.

If anyone has any suggestions I would appreciate it. I'm using a very plain vanilla ftp server.

Thanks,
 
If you have control over the FTP process then a crude and simple solution is to create a second file (let's call it SECOND.TXT) containing no data after your create the first file (let's call it FIRST.TXT)

Your program should wait until it detects SECOND.TXT before trying to open FIRST.TXT. It should then delete SECOND.TXT and process the data in FIRST.TXT.

Andrew
Hampshire, UK
 
Can't you just download it to a temp directory and then once finished (size check? im quite sure that is possible with FTP), just move it into the directory that your prog checks.

[bobafett] BobbaFet [bobafett]
Code:
if not Programming = 'Severe Migraine' then
                       ShowMessage('Eureka!');
 
Try opening the file. Probably it is blocked while the FTP program is writing it.

buho (A).
 
An extension to buho's suggestion - try to open the file exclusively. This will fail if the file is in use.


Hope this helps.

[vampire][bat]
 
Hi guys,

Thanks for your help - I actually tried a variation of what towerbase suggested(the idea of a file as a trigger hit me last night) and this works at the moment, although I would prefer it to be selfcontained within the program.

I will try earthandfire's suggestion next.

 
Hi guys,

Earthandfire, your suggestion worked great! I had my program check to see if it could open the file exclusively, and now it waits until it can do so before copying the file.

Thanks for all your help.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top