C# FtpWebRequest downloaded FTP files are empty

144 Views Asked by At

I have been working on a simple program to connect to FTP server and download a ZIP file. It makes the connection, authenticates and downloads the zip folder, but the contents are empty. I cant figure it out, please help! Thanks!

Console.WriteLine("downloading file . . . " + ary_connect[3]);

FtpWebRequest requestFileDownload = (FtpWebRequest)WebRequest.Create(ary_connect[0]);
requestFileDownload.Credentials = new NetworkCredential(ary_connect[1], ary_connect[2]);
requestFileDownload.Method = WebRequestMethods.Ftp.DownloadFile;
FtpWebResponse responseFileDownload = (FtpWebResponse)requestFileDownload.GetResponse();
            
byte[] buffer = new byte[32768];
using (Stream input = responseFileDownload.GetResponseStream())
{
  using (FileStream output = new FileStream(ary_connect[4] + ary_connect[3], FileMode.Create))
    {
      int bytesRead;
      while ((bytesRead = input.Read(buffer, 0, buffer.Length)) > 0)
      {
        output.Write(buffer, 0, bytesRead);
      }
    }
  }
0

There are 0 best solutions below