Problem with C # with files that I upload to FTP

I have a very strange problem when I upload files to FTP files (zip or gif).

I create a zip file with the code and upload it with the code to FTP. I can open any of these types of files when I create them on my local drive. But when I upload any of them to FTP and upload, it will show me a message for the .zip file as “unexpected end of archive” and for the type of .gif file after I upload them and try to open Windows XP image and fax viewer "Drawing Error":

I use this code to upload to FTP:

 FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://ftp.tim.com/" + fileName);
                request.Method = WebRequestMethods.Ftp.UploadFile;
            // This example assumes the FTP site uses anonymous logon.
            request.Credentials = new NetworkCredential(ftpuser,ftppass);

            // Copy the contents of the file to the request stream.
            StreamReader sourceStream = new StreamReader(filePath +"\\"+ fileName);
            byte[] fileContents = Encoding.UTF8.GetBytes(sourceStream.ReadToEnd());
            sourceStream.Close();
            request.ContentLength = fileContents.Length;
            request.KeepAlive = false;

            Stream requestStream = request.GetRequestStream();
            requestStream.Write(fileContents, 0, fileContents.Length);
            requestStream.Close();

            FtpWebResponse response = (FtpWebResponse)request.GetResponse();
            response.Close();
+3
source share
2 answers

This code:

StreamReader sourceStream = new StreamReader(filePath +"\\"+ fileName);
byte[] fileContents = Encoding.UTF8.GetBytes(sourceStream.ReadToEnd());

(UTF8)... GIF ZIP - , . .

- ReadAllBytes:

byte[] fileContents = File.ReadAllBytes("filepath");
+8

( utf8) . .

+3

All Articles