Skip to content

Commit 68e1e7f

Browse files
committed
Add write support to GetFileStreamAsync
1 parent d9dcb86 commit 68e1e7f

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

src/Foundatio.Storage.SshNet/Storage/SshNetFileStorage.cs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,24 @@ public async Task<Stream> GetFileStreamAsync(string path, StreamMode streamMode,
5252
if (String.IsNullOrEmpty(path))
5353
throw new ArgumentNullException(nameof(path));
5454

55-
if (streamMode is StreamMode.Write)
56-
throw new NotSupportedException($"Stream mode {streamMode} is not supported.");
57-
5855
EnsureClientConnected();
5956

6057
string normalizedPath = NormalizePath(path);
6158
_logger.LogTrace("Getting file stream for {Path}", normalizedPath);
6259

60+
if (streamMode is StreamMode.Write)
61+
{
62+
try
63+
{
64+
return await _client.OpenAsync(normalizedPath, FileMode.Create, FileAccess.Write, cancellationToken).AnyContext();
65+
}
66+
catch (SftpPathNotFoundException ex)
67+
{
68+
_logger.LogError(ex, "Unable to get file stream for {Path}: File Not Found", normalizedPath);
69+
return null;
70+
}
71+
}
72+
6373
try
6474
{
6575
return await _client.OpenAsync(normalizedPath, FileMode.Open, FileAccess.Read, cancellationToken).AnyContext();

tests/Foundatio.Storage.SshNet.Tests/Storage/SshNetStorageTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ public override Task WillRespectStreamOffsetAsync()
136136
return base.WillRespectStreamOffsetAsync();
137137
}
138138

139-
[Fact(Skip = "Write Stream is not yet supported")]
139+
[Fact]
140140
public override Task WillWriteStreamContentAsync()
141141
{
142142
return base.WillWriteStreamContentAsync();

0 commit comments

Comments
 (0)