views:

186

answers:

7

I have a .net app that is trying to ftp a file and we're ending up with 1 extra byte per line. My Line Separatro is Environment.NewLine which I beleive transaltes into \n\r. How many bytes is that?

+1  A: 

\n\r is 2 bytes.

Joshua
+1  A: 

Two bytes. One for \n and one for \r.

Jeff
+3  A: 

It's 2 bytes, but it should be \r\n not \n\r on windows OSs

Jack
+15  A: 

It depends on the encoding. In 8-bit encodings as well as UTF-8 it's 2 bytes. In UCS-2 or UTF-16 it's 4 bytes. In UCS-4 or UTF-32 it's 8 bytes.

But the problem is that you're probably FTPing in ASCII mode instead of IMAGE mode.

Ignacio Vazquez-Abrams
+1 for mentioning encodings
Amber
A: 

In ASCII encoding, \n is the Newline character (0x10), \r is the Carriage Return character (0x13).

As Jack has said already, the correct sequence is CR-LF, not vice versa.

FTP is probably adding LF characters to your stream if they are placed incorrectly and you are transmitting the file as Text.

cdonner
A: 

FTP software usually offer a binary and a text transfer mode. In text mode newline translation occurs during the transfer. This might be valid information, depending on what your problem is and why you asked the question.

Thomas Nilsson
+2  A: 

To answer the implied question:

To use binary-transfer rather than ascii-transfer in C#, use

FtpWebRequest reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://example.com"));
reqFTP.UseBinary = true;
BlueRaja - Danny Pflughoeft