c# - FTP download converts CrLf to Lf -


i'm downloading textfiles ftp-server using code (directories contains list of files/directories ftp server):

for (int = 0; <= directories.count - 1; i++)         {             int bytesread = 0;             byte[] buffer = new byte[2048];             string trnsfrpth = f.getconfig("temppath") + @"/" + directories[i].tostring();              if (directories[i].contains(".") && !(directories[i].tostring().equals(".") || directories[i].tostring().equals("..")))             {                 ftpwebrequest fileftprequest = (ftpwebrequest)webrequest.create(f.getconfig("ftp") + @"/" + directories[i].tostring());                 fileftprequest.usebinary = true;                 fileftprequest.credentials = credentials;                 fileftprequest.method = webrequestmethods.ftp.downloadfile;                  stream fileresponse = fileftprequest.getresponse().getresponsestream();                 filestream filestream = new filestream(trnsfrpth, filemode.create);                  while (true)                 {                     bytesread = fileresponse.read(buffer, 0, buffer.length);                      if (bytesread == 0)                         break;                      filestream.write(buffer, 0, bytesread);                 }                 filestream.close();              } 

the files have lf line break character. i'm not 100% sure files have cr lf line break begin with. if download them via filezilla, use cr lf. need cr lf version of files. wanted ask if i'm doing wrong here or if code ok , filezilla automatically converts files when downloading , have replace lf manually.

you have fileftprequest.usebinary = true; , using binary filestream on download side.

so it's not ftp client converts anything, want conversion filzilla apparently you're not getting.

you try usebinary=false docs vague effect.

a streamreader accepts '\n', replace while(true) part with

using (stream fileresponse = fileftprequest.getresponse().getresponsestream()) using (var reader = new streamreader(fileresponse)) {    string line;    while ((line = reader.readline()) != null)    {        something.writeline(line);  // here .net line ending    } } 

Comments

Popular posts from this blog

Android : Making Listview full screen -

javascript - Parse JSON from the body of the POST -

javascript - Chrome Extension: Interacting with iframe embedded within popup -