<PackageReference Include="SSH.NET" Version="2024.2.0" />

ChannelInputStream

sealed class ChannelInputStream : Stream
ChannelInputStream is a one direction stream intended for channel data.
using Renci.SshNet.Channels; using System; using System.IO; namespace Renci.SshNet.Common { internal sealed class ChannelInputStream : Stream { private readonly IChannelSession _channel; private long _totalPosition; private bool _isDisposed; public override bool CanRead => false; public override bool CanSeek => false; public override bool CanWrite => true; public override long Length { get { throw new NotSupportedException(); } } public override long Position { get { return _totalPosition; } set { throw new NotSupportedException(); } } internal ChannelInputStream(IChannelSession channel) { _channel = channel; } public override void Flush() { } public override long Seek(long offset, SeekOrigin origin) { throw new NotSupportedException(); } public override void SetLength(long value) { throw new NotSupportedException(); } public override int Read(byte[] buffer, int offset, int count) { throw new NotSupportedException(); } public override void Write(byte[] buffer, int offset, int count) { ThrowHelper.ThrowIfNull(buffer, "buffer"); if (offset + count > buffer.Length) throw new ArgumentException("The sum of offset and count is greater than the buffer length."); if (offset < 0 || count < 0) throw new ArgumentOutOfRangeException("offset", "offset or count is negative."); ThrowHelper.ThrowObjectDisposedIf(_isDisposed, this); if (count != 0) { _channel.SendData(buffer, offset, count); _totalPosition += count; } } protected override void Dispose(bool disposing) { if (!_isDisposed) { _isDisposed = true; if (disposing && _totalPosition > 0 && (_channel?.IsOpen ?? false)) _channel.SendEof(); } base.Dispose(disposing); } } }