.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) 
        {
            
            try
            {

                //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)))
                {
                    destination.Write(reader.ReadToEnd());
                    destination.Flush();
                }



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

            return true;
        }

Open in new window

csalernoAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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?
0
csalernoAuthor Commented:
I replaced the StreamWriter methods and was able to download without file corruption
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
csalernoAuthor Commented:
Figured it out by myself
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2008

From novice to tech pro — start learning today.