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;
request.Credentials = new NetworkCredential(ftpuser,ftppass);
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();
Nezir source
share