Sign in to follow this  
okuhan

FTP problem with Visual c++

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
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this