FTP problem with Visual c++

Started by
1 comment, last by okuhan 18 years, 10 months ago
I'm making a simple tool, that adds entries to a web diary. It downloads the diary page and updates it and sends it back to the server. I'm using MFC's CFtpConnection and GetFile() and Putfile() to accomplish this. The problem is that sometimes file download or upload gets stuck (some problem with the connection). Then on some rare occasions, the file is deleted or it's size is set to zero on the server. I was thinking that one solution could be to not overwrite the diary file on the server when uploading, but upload it with a different name. Then (if possible) have some script stored on the server do the overwriting, if the upload was successfull. I'm not sure if this is possible, though. Another problem is that the person who is using this tool is my grandma so it needs to be VERY simple. I'm not very familiar with network programming and there's probably a better way of doing this.
Advertisement
FTP supports delete and rename. Thus, you could:

0) delete file.tmp if it's there already
1) upload as file.tmp
2) verify the length is right of file.tmp
3) delete file
4) rename file.tmp to file

If you fail between step 3 and 4, you're still in a little bit of a pickle, as you'd ideally want transactional semantics for that. Sadly, you can't generally get that through FTP.

Regarding getting stuck, you could estimate the upload time based on the file size and some slop. If the upload time takes twice that or more, you can decide it's stuck, stop it, and start over. However, there's also the risk that the connection is just temporarily very slow, and you don't want to give up as long as you're making at least some progress.
enum Bool { True, False, FileNotFound };
Thanks :) I'll try that renaming thing. It's probably safe enough for this purpose

This topic is closed to new replies.

Advertisement