Skip to content

Consider revising behavior of SftpFileStream #194

@drieseng

Description

@drieseng

Our SftpFileStream currently performs separate householding for read and write mode.
This means - for example - that if you:

  1. open an existing file for read/write
  2. read two bytes
  3. write a single byte

The byte that you wrote in step 3 is actually written at position 0 instead of 2.

The following code fragment exposes this:

using (var client = new SftpClient(...))
{
    client.Connect();

    using (var s = client.Open(path, FileMode.CreateNew, FileAccess.Write))
    {
        s.Write(new byte[] { 5, 4, 3, 2, 1 }, 1, 3);
    }

    using (var s = client.Open(path, FileMode.Open, FileAccess.ReadWrite))
    {
        Console.WriteLine("#1: " + s.ReadByte());
        Console.WriteLine("#2: " + s.ReadByte());
        Console.WriteLine("#3: " + s.Position);

        s.WriteByte(7);
        s.Write(new byte[] {8, 9, 10, 11, 12}, 1, 3);

        Console.WriteLine("#4: " + s.Position);
    }
}

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions