How to download .zip file format using C # code?
Here is the code I use to download. Just highlight if I upload a .txt file, it works great. If I download a ZIP file, it downloads a ZIP file, but I cannot open it. He complains that the .zip is in the wrong format. I have doubts about how I write a file on a local drive.
reference
string ftpServerIP = FTPServer; string ftpUserID = FTPUser; string ftpPassword = FTPPwd; FileInfo fileInf = new FileInfo(FileName); string uri = "ftp://" + ftpServerIP + "/" + fileInf.Name; FtpWebRequest reqFTP = (FtpWebRequest)FtpWebRequest.Create(uri); //new Uri("ftp://" + ftpServerIP + DestinationFolder + fileInf.Name)); reqFTP.Credentials = new NetworkCredential(ftpUserID, ftpPassword); reqFTP.EnableSsl = true; reqFTP.KeepAlive = false; reqFTP.UseBinary = true; //reqFTP.UsePassive = true; reqFTP.Method = WebRequestMethods.Ftp.DownloadFile; ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(AcceptAllCertifications); //Stream strm = reqFTP.GetRequestStream(); StreamReader reader = new StreamReader(reqFTP.GetResponse().GetResponseStream()); StreamWriter writer = new StreamWriter(Path.Combine(FolderToWriteFiles, FileName), false); writer.Write(reader.ReadToEnd()); return true;
Jango source share