You don't want to read the raw data into a string, you should be reading it into a byte array. The .NET string is made up of two-byte characters.
You should use a BinaryReader
, or better yet, write it directly to the file, without reading it into memory first, using CopyTo()
private static void GetFile(string file, bool inBound)
{
// Removed the FTP setup code
using (Stream responseStream = response.GetResponseStream())
{
using (Stream outputStream = File.OpenWrite(@".\" + file))
{
try
{
responseStream.CopyTo(outputStream);
}
catch (Exception e)
{
// Removed Exception code
}
}
}
}