diff --git a/src/Foundatio.Storage.SshNet/Storage/SshNetFileStorage.cs b/src/Foundatio.Storage.SshNet/Storage/SshNetFileStorage.cs index 1c1a28c..28497c9 100644 --- a/src/Foundatio.Storage.SshNet/Storage/SshNetFileStorage.cs +++ b/src/Foundatio.Storage.SshNet/Storage/SshNetFileStorage.cs @@ -52,14 +52,24 @@ public async Task 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(); diff --git a/tests/Foundatio.Storage.SshNet.Tests/Storage/SshNetStorageTests.cs b/tests/Foundatio.Storage.SshNet.Tests/Storage/SshNetStorageTests.cs index d2918be..d88e359 100644 --- a/tests/Foundatio.Storage.SshNet.Tests/Storage/SshNetStorageTests.cs +++ b/tests/Foundatio.Storage.SshNet.Tests/Storage/SshNetStorageTests.cs @@ -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();