Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6929575
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:20:07+00:00 2026-05-27T11:20:07+00:00

I have zip file in ftp server,this zip file contain more then one xml

  • 0

I have zip file in ftp server,this zip file contain more then one xml file in it,i want to download this zipfile and save to local disk,i have write below code,i download file but when i try to Extract this zip it throw me error that File is corrupted……

FtpWebRequest request = (FtpWebRequest)WebRequest.Create(_remoteHost + file);
request.Method = WebRequestMethods.Ftp.DownloadFile;
request.Credentials = new NetworkCredential(_remoteUser, _remotePass);
FtpWebResponse response = (FtpWebResponse)request.GetResponse();
Stream responseStream = response.GetResponseStream();
StreamReader reader = new StreamReader(responseStream);

StreamWriter writer = new StreamWriter(destination);
writer.Write(reader.ReadToEnd());

writer.Close();
reader.Close();
response.Close();
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T11:20:08+00:00Added an answer on May 27, 2026 at 11:20 am

    You are channeling the result of the FTP request through a StreamReader. This has the usually beneficial effect of handling character encoding, but is not something you ever want to do when dealing with binary data (i.e. a zip file). Instead, you should read the data directly from the stream. Something like:

    FtpWebRequest request = (FtpWebRequest)WebRequest.Create(_remoteHost + file);
    request.Method = WebRequestMethods.Ftp.DownloadFile;
    request.Credentials = new NetworkCredential(_remoteUser, _remotePass);
    FtpWebResponse response = (FtpWebResponse)request.GetResponse();
    Stream responseStream = response.GetResponseStream();
    
    // Copy the data from the responseStream to destination 1k at a time (feel free to increase buffer size)
    byte[] buffer = new byte[1024];
    for (int amountRead = responseStream.Read(buffer, 0, buffer.Length); amountRead > 0; amountRead = responseStream.Read(buffer, 0, buffer.Length))
    {
        destination.Write(buffer, 0, amountRead);
    }
    destination.Flush();
    
    response.Close();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can't find anything on this one. I have a zip file on my server
I have .zip file which contain csv data. I am reading .zip file using
I have always wondered about this. So many application setups have a zip file
I want to pack the project into a zip-file and have the build date
The thing is like this. I have a zip file with images that uncompressing
I have a zip file which has one base folder inside it with other
I need to get this file ftp://1034733:ze3Kt699vy14@idx.living.net/idx_fl_ftp_down/idx_ftmyersbeach_dn/ftmyersbeach_data.zip to my site's server. THis seems like
I am writing a code to upload a zip file to an ftp server.
Have made backup script that does well: makes backup zip-file and then uploads it
I have a zip file embedded in my jar and want to read the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.