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

  • Home
  • SEARCH
  • 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 6080959
In Process

The Archive Base Latest Questions

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

Finding some problems copying a zip file from an FTP location. It is just

  • 0

Finding some problems copying a zip file from an FTP location. It is just copying and empty file so I think there is something wrong with my use of StreamReader or StreamWriter.

Here is the code:

//read through directory details response
string line = reader.ReadLine();
while (line != null)
{
    if (line.EndsWith("zip")) //"d" = dir don't need "." or ".." dirs
    {
        FtpWebRequest downloadRequest = (FtpWebRequest)FtpWebRequest.Create("ftp://" + ftpHost + line); //new Uri("ftp://" + ftpServerIP + DestinationFolder + fileInf.Name));
        downloadRequest.Credentials = new NetworkCredential(ConfigurationManager.AppSettings["FilesUser"], ConfigurationManager.AppSettings["FilesPass"]);
        downloadRequest.KeepAlive = false;
        downloadRequest.UseBinary = true;
        downloadRequest.Method = WebRequestMethods.Ftp.DownloadFile;

        string folderToWrite = HttpContext.Current.Server.MapPath("~/Routing/RoutingFiles/");
        string folderToSave = HttpContext.Current.Server.MapPath("~/Routing/");

        StreamReader downloadRequestReader = new StreamReader(downloadRequest.GetResponse().GetResponseStream());
        DirectoryInfo downloadDirectory = new DirectoryInfo(folderToWrite);

        FileInfo file = new FileInfo(Path.Combine(downloadDirectory.FullName, line));
        if (!file.Exists)
        {
            StreamWriter writer = new StreamWriter(Path.Combine(folderToWrite, line), false);
            writer.Write(downloadRequestReader.ReadToEnd());

            using (var downloadResponseStream = response.GetResponseStream())
            {
            }
        }
    }
}

By the time it gets to the bottom of that section, the file has been copied but is empty so I don’t think I’m reading the stream correctly for a zip file. Anyone any ideas? I’ve seen talk of FileStream being better for downloading Zip files, but I couldn’t get that to work either.

Thanks.

  • 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-23T11:07:17+00:00Added an answer on May 23, 2026 at 11:07 am

    Here is an example that downloads a file from an ftp.

    try
    {
        FtpWebRequest request = (FtpWebRequest)WebRequest.Create(ftpAddr + "test.zip");
        request.Credentials = new NetworkCredential(userName, password);
        request.UseBinary = true; // Use binary to ensure correct dlv!
        request.Method = WebRequestMethods.Ftp.DownloadFile;
    
        FtpWebResponse response = (FtpWebResponse)request.GetResponse();
        Stream responseStream = response.GetResponseStream();
        FileStream writer = new FileStream("test.zip", FileMode.Create);
    
        long length = response.ContentLength;
        int bufferSize = 2048;
        int readCount;
        byte[] buffer = new byte[2048];
    
        readCount = responseStream.Read(buffer, 0, bufferSize);
        while (readCount > 0)
        {
            writer.Write(buffer, 0, readCount);
            readCount = responseStream.Read(buffer, 0, bufferSize);
        }
    
        responseStream.Close();
        response.Close();
        writer.Close();
    
    }
    catch (Exception e)
    {
        Console.WriteLine(e.ToString());
    }
    

    Edit I’m sorry for the error in previous code.

    When correcting my previous code I found the following resource useful: example

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've moved from iOS applications development to android so I'm facing some problems finding
I'm finding some problems with a query that returns the sum of a field
I got some problems with finding a bug in php/mysql application, and I wonder
I am manually converting code from Java (1.6) to C# and finding some difficulty
There is some easily available information on finding the status of a battery, or
I am learning asp.net but I'm finding some problems. My doubt is how to
Hi I Have some problems finding the right information about this and would be
I was working on some grouping problems at my work. There are quite a
I have some problems with finding and replacing words in PHP files, especially when
Hey, I'm having some problems writing a batch file where I need to specify

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.