This project is read-only.

Download ZIP Files

Nov 28, 2014 at 4:40 PM
Edited Nov 28, 2014 at 4:42 PM
Hello, I'm downloading ZIP file from a ftp server using your library.

The file is downloaded, seem to have the correct size, but non the less it is corrupted and can't be opened.
Neither by the process in which it's running or the windows explorer.

The files i'm downloading are smaller than 200KB

This is my code.
 try
            {
                using (Stream s = _ftpClient.OpenRead(sourceFileFullPath))
                {
                    if (s.Length != 0)
                    {

                        using (FileStream fileStream = System.IO.File.Create(fileFullPath, (int)s.Length))
                        {

                            var bytesInStream = new byte[s.Length];
                            s.Read(bytesInStream, 0, (int)bytesInStream.Length);

                            fileStream.Write(bytesInStream, 0, bytesInStream.Length);

                            newFile = new FileInfo(fileFullPath);
                        }
                    }

                    //s.Close();

                }
            }
            catch (IOException ioException)
            {
                Console.WriteLine("IOException: " + ioException.Message);
            }
            catch (SocketException socketException)
            {
                Console.WriteLine("SocketException: " + socketException.Message);
            }
            catch (FtpCommandException ftpCommandException)
            {
                Console.WriteLine("FtpCommandException: " + ftpCommandException.Message);
            }
            catch (Exception)
            {
                throw;
            }
Did anyone else had this issue?
Coordinator
Nov 28, 2014 at 5:04 PM
Use a loop and a buffer of about 8192 instead of trying to read the whole file in one swoop like you're doing. It doesn't work, it's not even a good idea to blindly allocate a buffer the size of the file like that. See the various other threads where doing that has bitten people.