FtpWebRequest on Reading file just after Uploading give Access denied error
We are using FTPWebRequest class in my project to upload PDF files. For uploading the File we are using Write method by getting a GetRequestStream() from object of (FtpWebRequest)WebRequest.
After uploading files we read the file to get length(size of file). We are using GetResponseStream method of FtpWebResponse for the same.
Everything work fines when files size is less but when heavy files are uploaded then it gives '550' error of access denied.
It seems to me that when big files are being written on FTP and after closing the stream if we immediately go to read the file then it creates problem of access denied may be FTP Server has not removed the lock from file or its still writing the file from stream.
How can be get rid of this problem. Is there is any Event or a Way to find out that File has been successfully written on FTP Server when we are closing the Stream which is being used to Upload file?
Though I don't know why but following steps helped me to solve this problem
Set the buffer size to low on FTP Server, generally it is 64 K you can set it to 32 k
Send the chunks to Server, rather then sending it one go on stream, because when sending it in One go , data is kept in buffer and when we make request to read the file error is prompted.