It depends on the server and timing. Some server can response with "Access denied" if the file is not completed, other server can read up to the current length of the incomplete file.
You should use some synchronization design to mitigate the issue. I can think of these:
Add the .part
file extension to the file name and never download files with this extension. After finished upload rename the file as follows:
// upload the file
client.PutFile("file.txt", "/file.txt.part");
// rename it
client.Rename("/file.txt.part", "/file.txt");
Or upload the file into special incoming directory, then move it to its appropriate location as follows:
// upload the file
client.PutFile("file.txt", "/incoming/file.txt");
// move it
client.Rename("/incoming/file.txt", "/file.txt");
Or create the .lock
file to indicate the file is being currently uploaded. Remove the file after upload is finished.
// upload process...
// create empty file .lock indicating the file is being transferred
client.PutFile(new MemoryStream(), "/file.txt.lock");
// upload the file
client.PutFile("file.txt", "/file.txt");
// remove the .lock file to indicate the transfer is completed
client.DeleteFile("/file.txt.lock");
// download process...
// wait until the file is complete
// note: adding some timeout check is needed to prevent deadlock in case
// the upload process failed and the .lock file remains on server
while (client.FileExists("/file.txt.lock"))
Thread.Sleep(1000);
// download the file
client.GetFile("/file.txt", "file.txt");
If none of the above is possible, you can try re-download with timeout approach as described here.