Take the 2-minute tour ×

I have two services client and server. Client upload file on some ftp and server download it. So there can occur situation when client do not finish upload file and server already start download this file. In that situation i have cuted file. How can solve it?

For example when i upload and at the same time download it using FileZilla the download process waiting for upload finish and then start downloading. So downloaded file not correpted.

Here is uploading code:

request = (FtpWebRequest)FtpWebRequest.Create(""
+ file7z); 
request.Credentials = new NetworkCredential("login", "pass"); 
request.Method = WebRequestMethods.Ftp.UploadFile; 
request.Proxy = null;        
request.UsePassive = true; request.UseBinary = true;

byte[] fileContents = File.ReadAllBytes(all7zfullpath); 
request.ContentLength = fileContents.Length;

Stream stRequest = request.GetRequestStream(); 
stRequest.Write(fileContents, 0, fileContents.Length); 
share|improve this question
add comment

2 Answers

up vote 0 down vote accepted

One solution is to upload the file with a special name or in a special folder such that the downloader won't recognize it. Then have the client move/rename the file once it's been completely uploaded so that the server will recognize it.

share|improve this answer
Good idea.. I will use if dont find another solution... –  user283397 Mar 1 '10 at 5:24
Uploading into a directory outside of the document root is an awesome idea as well - this is one of a few steps needed to ensure an uploader isn't used maliciously. The other steps include checking/verifying the content of files once they're uploaded; i.e. if it's supposed to be a GIF it better not be PHP code! –  pbr Jan 26 '11 at 21:52
add comment

If you have control over the FTP server, you could simply lock any file that is currently being uploaded. Then the download attempt will fail until the upload is complete. This has the downside of the server having to retry every so often.

share|improve this answer
add comment

Your Answer

