Stream class doesn’t detect line breaks

Updated on June 29, 2017 in [A] C# .Net
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
0 on June 29, 2017
public void AlternativeUpload(string fileName)
        string oldPath = "My local file";
        string newPath = "FTP Adress";
            FtpWebRequest ftp = (FtpWebRequest)FtpWebRequest.Create(newPath);
            ftp.Credentials = new NetworkCredential(FTPUserName, FTPPassword);
            ftp.KeepAlive = true;
            ftp.UseBinary = true;
            ftp.Method = WebRequestMethods.Ftp.UploadFile;
      byte[] buffer=System.Text.Encoding.Default.GetBytes(File.ReadAllText(oldPath,System.Text.Encoding.Default));
            ftp.ContentLength = buffer.Length;
            Stream ftpstream = ftp.GetRequestStream();
            ftpstream.Write(buffer, 0, buffer.Length);
        catch (Exception ex)
            throw ex;

This is the code I use for uploading txt files to the ftp. Problem is, the text I uploaded doesn’t contain “\n” by the server side.

PS: Local file has line breaks. I think real issue is with the Stream class.

  • Liked by