You need to use a loop to read the stream until 0 is returned. You also only need to write the number of bytes returned by istream.Read(), not the length of the buffer as your buffer may not be filled and that will surely corrupt the file.

You need to use a loop to read the stream until 0 is returned. You also only need to write the number of bytes returned by istream.Read(), not the length of the buffer as your buffer may not be filled and that will surely corrupt the file.

Thank you, i re-wrote the "save" part to this:

using (Stream istream = conn.OpenRead(fileName))
{
FileStream fileoutput = new FileStream(localPath, FileMode.Create, System.IO.FileAccess.Write);
try
{
// istream.Position is incremented accordingly to the reads you perform
// istream.Length == file size if the server supports getting the file size
// also note that file size for the same file can vary between ASCII and Binary
// modes and some servers won't even give a file size for ASCII files! It is
// recommended that you stick with Binary and worry about character encodings
// on your end of the connection.
byte[] buffer = new byte[8 * 1024];
int len;
while ((len = istream.Read(buffer, 0, buffer.Length)) > 0)
{
fileoutput.Write(buffer, 0, len);
}
}
finally
{
fileoutput.Close();
istream.Close();
}
}