How to tell when a file transfer has completed (Server to Client)

.net, ftpwebrequest

Solution

Check the `FtpWebResponse.StatusCode` for success. e.g. `FtpStatusCode.ClosingData`

Problem

I am pulling a file from an ftp server and I'm having trouble feeling comfortable with my method of verifying the transfer was completed successfully. It feels like there must be a more concrete way of detecting a successful transfer. Any ideas? My Code: ``` var request = (FtpWebRequest)FtpWebRequest.Create(ftpFilePath); request.KeepAlive = false; request.UseBinary = true; request.UsePassive = false; request.Credentials = new NetworkCredential("Username", "Password"); request.Method = WebRequestMethods.Ftp.DownloadFile; FtpWebResponse response = (FtpWebResponse)request.GetResponse(); using (var stream = response.GetResponseStream()) { using (var reader = new StreamReader(stream)) { contents = reader.ReadToEnd(); } } //Check to see if transfer was successful if (response.StatusDescription.StartsWith("2")) transferSuccessful = true; ```

Original source