1

I'm playing with using FTP to periodically upload small data files from a program to a server. Users access the data from a web page which reads the data with the javascript XMLHttpRequest function. It all seems to work but I'm struggling with some problems caused by the FTP and XMLHttpRequest getting in each others way. The only idea I've come up with is to retry failed uploads and detecting either failed XMLHttpRequests or those that return incomplete data and retrying those.

I'd like to use something simple like FTP since users of the application will probably not be able to host servers (they are likely behind NAT routers and have no fixed IP numbers) and not have access to any fancy external servers.

Anyone have any suggestions?

2
  • How is that working? Sounds like it would violate same-origin-policy. Commented Sep 20, 2011 at 13:53
  • 1
    Not sure what you mean. The javascript and the data files are stored in the same directory on the same server. Commented Sep 20, 2011 at 14:11

3 Answers 3

1

What if you avoid file locking problems by uploading the file under a temporary name and then renaming it?

pseduo code:

FTPSend "c:\readme.txt" /as "readme.txt.tmp" if error retry FTPSend FTPRename "readme.txt.tmp" /as "readme.txt" if error retry rename 

Of course you would also want to limit the amount of time you spend retrying a failed operation so it doesn't get hung in a loop.

Sign up to request clarification or add additional context in comments.

1 Comment

Good idea. On the servers I tried one has to delete the old file b4 you can rename the newly uploaded file. So there's a window when the file does not exist. Odd that one can replace a existing file with an upload but not with a rename. Still probably better than what I'm doing.
1

Scrap FTP (it is not NAT friendly) and do your uploads over HTTP. You already have a system in place that can handle HTTP (since you are using XHR). You can accept overloads via a POST request and include some integrity checking before overwriting existing content or announcing new content.

3 Comments

The upload is done internally to a c++ application using the WinINet api functions. I'm not familiar with the http parts of WinINet; would those be an example of what you are suggesting?
I've tried to upload the file with WinINet http post. All the status values coming back are ok but nothing ever gets written to the server. It doesn't matter if the file exists or not before the post.
POST doesn't create files (PUT does), it just sends a message, you would need a handler to parse the form data and create the file.
0

My app is intended for use by people who don't have access to a server they can control. I.e. they are likely to use file space provided by their ISP or some free FTP site. Therefore any http post function will not work.

Therefore, I'm using FTP with the rename suggestion above.

1) delete file TEMP.htm if it exists 2) upload filr TEMP.htm 3) delete the target file, retry some number of times 4) rename TEMP.htm to target file

There some time between 3) and 4) when there is no target so web refernces to it might fail. The page that uses the files also has to retry the access.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.