.Net Download corrupting file

I have a method that downloads a self-extracting zip file to a client and the file keeps getting downloaded corrupt. I had used a WebClient method prior and had no problem with corruption and changed because I needed to be able to adjust TIMEOUT settings.

        /// <summary>
        /// Performs the downloading of the update package file to run on the client
        /// </summary>
        /// <param name="Username"></param>
        /// <param name="Password"></param>
        /// <param name="Address"></param>
        /// <param name="Timeout"></param>
        /// <param name="FileName"></param>
        /// <param name="DownloadPath"></param>
        /// <returns>A boolean whether the call was successful</returns>
        public bool DownloadUpdate(string Username, string Password, string Address, int Timeout, string FileName, string DownloadPath) 

                //serverPath = "ftp://x.x.x.x/tmp/myfile.txt";

                FtpWebRequest request = (FtpWebRequest)WebRequest.Create(string.IsNullOrEmpty(Address) ? "ftp://"+AppDownloadPath : Address.Replace("http://","ftp://"));

                request.KeepAlive = true;
                request.UsePassive = true;
                request.UseBinary = true;
                request.Proxy = null;

                request.Method = WebRequestMethods.Ftp.DownloadFile;                
                request.Credentials = new NetworkCredential(Username, Password);

                // Read the file from the server & write to destination                
                using (FtpWebResponse response = (FtpWebResponse)request.GetResponse()) 
                using (Stream responseStream = response.GetResponseStream())
                using (StreamReader reader = new StreamReader(responseStream,true))
                using (StreamWriter destination = new StreamWriter(System.IO.Path.Combine(DownloadPath, FileName)))

            catch (SystemException WebEx)
                eventLogger.LogError("DownloadUpdate", WebEx.Message);
                return false;

            return true;

Open in new window

Who is Participating?
csalernoConnect With a Mentor Author Commented:
I replaced the StreamWriter methods and was able to download without file corruption
Bob LearnedCommented:
Does corruption mean that the bytes are mangled, or the download was not complete?  Do you know the file size or a CRC checksum before you start downloading?
csalernoAuthor Commented:
Figured it out by myself
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.