Jump to content
  • Advertisement
Sign in to follow this  
okuhan

FTP problem with Visual c++

This topic is 4737 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Thanks :) I'll try that renaming thing. It's probably safe enough for this purpose

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!