Skip to content

Commit

Permalink
Add write support to GetFileStreamAsync
Browse files Browse the repository at this point in the history
  • Loading branch information
ejsmith committed Nov 26, 2024
1 parent d9dcb86 commit 68e1e7f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
16 changes: 13 additions & 3 deletions src/Foundatio.Storage.SshNet/Storage/SshNetFileStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,24 @@ public async Task<Stream> GetFileStreamAsync(string path, StreamMode streamMode,
if (String.IsNullOrEmpty(path))
throw new ArgumentNullException(nameof(path));

if (streamMode is StreamMode.Write)
throw new NotSupportedException($"Stream mode {streamMode} is not supported.");

EnsureClientConnected();

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

if (streamMode is StreamMode.Write)
{
try
{
return await _client.OpenAsync(normalizedPath, FileMode.Create, FileAccess.Write, cancellationToken).AnyContext();
}
catch (SftpPathNotFoundException ex)
{
_logger.LogError(ex, "Unable to get file stream for {Path}: File Not Found", normalizedPath);
return null;
}
}

try
{
return await _client.OpenAsync(normalizedPath, FileMode.Open, FileAccess.Read, cancellationToken).AnyContext();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public override Task WillRespectStreamOffsetAsync()
return base.WillRespectStreamOffsetAsync();
}

[Fact(Skip = "Write Stream is not yet supported")]
[Fact]
public override Task WillWriteStreamContentAsync()
{
return base.WillWriteStreamContentAsync();
Expand Down

0 comments on commit 68e1e7f

Please sign in to comment.