//--------< send file content each time 512 size >------- private bool SendFile(ICommService service, string file) { long blockSize = 512; try { string filename = Path.GetFileName(file); service.OpenFileForWrite(filename); FileStream fs = File.Open(file, FileMode.Open, FileAccess.Read); int bytesRead = 0; while (true) { long remainder = (int)(fs.Length - fs.Position); if (remainder == 0) { break; } long size = Math.Min(blockSize, remainder); byte[] block = new byte[size]; bytesRead = fs.Read(block, 0, block.Length); service.WriteFileBlock(block); } fs.Close(); service.CloseFile(); return(true); } catch (Exception ex) { Console.Write("\n can't open {0} for writing - {1}", file, ex.Message); return(false); } }