Skip to content

Commit f38c7ce

Browse files
committed
SftpFileStream: In Append mode, create the remote file if it does not already exist.
SftpFileStream: In Append mode, create the remote file if it does not already exist. Fixes issue #266.
1 parent c2552e4 commit f38c7ce

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Ctor_FileModeAppend_FileAccessWrite.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ protected override void SetupData()
4646
protected override void SetupMocks()
4747
{
4848
SftpSessionMock.InSequence(MockSequence)
49-
.Setup(p => p.RequestOpen(_path, Flags.Write | Flags.Append, false))
49+
.Setup(p => p.RequestOpen(_path, Flags.Write | Flags.Append | Flags.CreateNewOrOpen, false))
5050
.Returns(_handle);
5151
SftpSessionMock.InSequence(MockSequence)
5252
.Setup(p => p.CalculateOptimalReadLength((uint) _bufferSize))
@@ -161,7 +161,7 @@ public void WriteShouldStartWritingAtEndOfFile()
161161
[TestMethod]
162162
public void RequestOpenOnSftpSessionShouldBeInvokedOnce()
163163
{
164-
SftpSessionMock.Verify(p => p.RequestOpen(_path, Flags.Write | Flags.Append, false), Times.Once);
164+
SftpSessionMock.Verify(p => p.RequestOpen(_path, Flags.Write | Flags.Append | Flags.CreateNewOrOpen, false), Times.Once);
165165
}
166166

167167
[TestMethod]

src/Renci.SshNet/Sftp/SftpFileStream.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ internal SftpFileStream(ISftpSession session, string path, FileMode mode, FileAc
222222
switch (mode)
223223
{
224224
case FileMode.Append:
225-
flags |= Flags.Append;
225+
flags |= Flags.Append | Flags.CreateNewOrOpen;
226226
break;
227227
case FileMode.Create:
228228
_handle = _session.RequestOpen(path, flags | Flags.Truncate, true);

0 commit comments

Comments
 (0)