NULL Line generated in the FTP Textfile send code
I am writing a FTP Text file send method in managed C++. The objective is to send data files (containing small lines) over FTP to a remote server. This piece of code sends an additional line with null (hex 00) to the remote server.
If have 3 lines of text as below,
Begin Line
LudMila Koganer
End Line
the server will have four lines. the first three lines excaly matches up
but it adds an additional line which has a 1 character hex'00' on it.
The hex 00 is originating from the last byte on the file.
(There is a x'00' after the end Line)
Apparently this is the last byte in any text file indicating end of file. I dont
know why the hex zero is replaced with a CRLF and a hex zero which results in
additional line.
I am not sure how to avoid this third line that ends up on the remote server.
Thanks for your suggestions.
StreamWriter^ sw = gcnew StreamWriter(ns);
String^ line;
String^ crlf = "\r\n";
String^ NULL = "\0";
int count = 0;
try
{
while (sr->Peek() >= 0 )
{
line = sr->ReadLine();
count = count + 1;
if (line != NULL)
{
sw->Write(line);
sw->Write(crlf);
}
}
sr->Close();
sw->Flush();
sw->Close();
Console::WriteLine(L"Successfully Written {0} records", count);
}
catch (Exception^ e)
}
...
...
}

