- FileInfo fileInfo = new FileInfo(filename);
-
-
- string sFtpHostSite = "ftp://" + _sFtpHost.Replace("\0", "");
-
-
- FtpWebRequest request = (FtpWebRequest)WebRequest.Create(sFtpHostSite + @"/" + fileInfo.Name);
- request.Method = WebRequestMethods.Ftp.UploadFile;
-
- request.Credentials = new NetworkCredential(_sFtpUserId.Trim().Replace("\0", ""), _sFtpPwd.Trim().Replace("\0", ""));
- request.KeepAlive = false;
- request.Method = "STOR";
- request.UseBinary = true;
-
-
-
- StreamReader sourceStream = new StreamReader(_sLocalPath.Replace("\0","") + fileInfo.Name);
- byte[] fileContents = Encoding.UTF8.GetBytes(sourceStream.ReadToEnd());
- sourceStream.Close();
- request.ContentLength = fileContents.Length;
-
- Stream requestStream = request.GetRequestStream();
- requestStream.Write(fileContents, 0, fileContents.Length);
- requestStream.Close();
-
- FtpWebResponse response = (FtpWebResponse)request.GetResponse();
-
- Console.WriteLine("Upload File Complete, status {0}", response.StatusDescription);
-
- response.Close();
- }
- catch (Exception oErMsg1)
- {
-
- Console.WriteLine(oErMsg1.Message, "Error Occurred while uploading file to FTP server.");
-
- }
Does anyone knows why when the file gets uploaded to the FTP-Server it is not the same as the Local-directory?
Explain:
I compress zip some folders on the local computer using 7z library when I open the compressed zip file on my local for test it open and I can unzip it with no problem but once I upload it using my c# FTP-Upload the size of the file is different and when I download it regardless the FTP client used for download the file is corrupted I can't open it.
Please see my code for more detail
Thanks in advance
AL