mirror of
https://github.com/sshnet/SSH.NET.git
synced 2026-10-29 07:07:02 +08:00
Add CreateShellStream method and ShellStream class to work with shells
Make aes256-ctr encryption to be default one
This commit is contained in:
@@ -730,6 +730,9 @@
|
||||
<Compile Include="..\Renci.SshNet\Shell.cs">
|
||||
<Link>Shell.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\Renci.SshNet\ShellStream.cs">
|
||||
<Link>ShellStream.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\Renci.SshNet\SshClient.cs">
|
||||
<Link>SshClient.cs</Link>
|
||||
</Compile>
|
||||
@@ -755,7 +758,7 @@
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<ProjectExtensions>
|
||||
<VisualStudio>
|
||||
<UserProperties ProjectLinkReference="2f5f8c90-0bd1-424f-997c-7bc6280919d1" ProjectLinkerExcludeFilter="\\?desktop(\\.*)?$;\\?silverlight(\\.*)?$;\.desktop;\.silverlight;\.xaml;^service references(\\.*)?$;\.clientconfig;^web references(\\.*)?$" />
|
||||
<UserProperties ProjectLinkerExcludeFilter="\\?desktop(\\.*)?$;\\?silverlight(\\.*)?$;\.desktop;\.silverlight;\.xaml;^service references(\\.*)?$;\.clientconfig;^web references(\\.*)?$" ProjectLinkReference="2f5f8c90-0bd1-424f-997c-7bc6280919d1" />
|
||||
</VisualStudio>
|
||||
</ProjectExtensions>
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
|
||||
@@ -696,6 +696,9 @@
|
||||
<Compile Include="..\Renci.SshNet\Shell.cs">
|
||||
<Link>Shell.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\Renci.SshNet\ShellStream.cs">
|
||||
<Link>ShellStream.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\Renci.SshNet\SshClient.cs">
|
||||
<Link>SshClient.cs</Link>
|
||||
</Compile>
|
||||
@@ -722,7 +725,7 @@
|
||||
<FlavorProperties GUID="{A1591282-1198-4647-A2B1-27E5FF5F6F3B}">
|
||||
<SilverlightProjectProperties />
|
||||
</FlavorProperties>
|
||||
<UserProperties ProjectLinkerExcludeFilter="\\?desktop(\\.*)?$;\\?silverlight(\\.*)?$;\.desktop;\.silverlight;\.xaml;^service references(\\.*)?$;\.clientconfig;^web references(\\.*)?$" ProjectLinkReference="2f5f8c90-0bd1-424f-997c-7bc6280919d1" />
|
||||
<UserProperties ProjectLinkReference="2f5f8c90-0bd1-424f-997c-7bc6280919d1" ProjectLinkerExcludeFilter="\\?desktop(\\.*)?$;\\?silverlight(\\.*)?$;\.desktop;\.silverlight;\.xaml;^service references(\\.*)?$;\.clientconfig;^web references(\\.*)?$" />
|
||||
</VisualStudio>
|
||||
</ProjectExtensions>
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
|
||||
@@ -704,6 +704,9 @@
|
||||
<Compile Include="..\Renci.SshNet\Shell.cs">
|
||||
<Link>Shell.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\Renci.SshNet\ShellStream.cs">
|
||||
<Link>ShellStream.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\Renci.SshNet\SshClient.cs">
|
||||
<Link>SshClient.cs</Link>
|
||||
</Compile>
|
||||
@@ -726,7 +729,7 @@
|
||||
<Import Project="$(MSBuildExtensionsPath)\Microsoft\Silverlight for Phone\$(TargetFrameworkVersion)\Microsoft.Silverlight.CSharp.targets" />
|
||||
<ProjectExtensions>
|
||||
<VisualStudio>
|
||||
<UserProperties ProjectLinkerExcludeFilter="\\?desktop(\\.*)?$;\\?silverlight(\\.*)?$;\.desktop;\.silverlight;\.xaml;^service references(\\.*)?$;\.clientconfig;^web references(\\.*)?$" ProjectLinkReference="2f5f8c90-0bd1-424f-997c-7bc6280919d1" />
|
||||
<UserProperties ProjectLinkReference="2f5f8c90-0bd1-424f-997c-7bc6280919d1" ProjectLinkerExcludeFilter="\\?desktop(\\.*)?$;\\?silverlight(\\.*)?$;\.desktop;\.silverlight;\.xaml;^service references(\\.*)?$;\.clientconfig;^web references(\\.*)?$" />
|
||||
</VisualStudio>
|
||||
</ProjectExtensions>
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
|
||||
@@ -22,6 +22,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Renci.SshNet.Tests.NET35",
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Renci.SshNet.WindowsPhone", "Renci.SshNet.WindowsPhone\Renci.SshNet.WindowsPhone.csproj", "{3AD3EDF0-702E-4A91-8735-DCE4659AA54C}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Zlib DLL", "Zlib\Zlib DLL.csproj", "{9816BA86-9250-4C00-A912-25F07F8677D1}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(TeamFoundationVersionControl) = preSolution
|
||||
SccNumberOfProjects = 7
|
||||
@@ -129,6 +131,16 @@ Global
|
||||
{3AD3EDF0-702E-4A91-8735-DCE4659AA54C}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
|
||||
{3AD3EDF0-702E-4A91-8735-DCE4659AA54C}.Release|Mixed Platforms.Build.0 = Release|Any CPU
|
||||
{3AD3EDF0-702E-4A91-8735-DCE4659AA54C}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{9816BA86-9250-4C00-A912-25F07F8677D1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{9816BA86-9250-4C00-A912-25F07F8677D1}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{9816BA86-9250-4C00-A912-25F07F8677D1}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
|
||||
{9816BA86-9250-4C00-A912-25F07F8677D1}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
|
||||
{9816BA86-9250-4C00-A912-25F07F8677D1}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{9816BA86-9250-4C00-A912-25F07F8677D1}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{9816BA86-9250-4C00-A912-25F07F8677D1}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{9816BA86-9250-4C00-A912-25F07F8677D1}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
|
||||
{9816BA86-9250-4C00-A912-25F07F8677D1}.Release|Mixed Platforms.Build.0 = Release|Any CPU
|
||||
{9816BA86-9250-4C00-A912-25F07F8677D1}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
||||
@@ -213,6 +213,7 @@ namespace Renci.SshNet
|
||||
|
||||
this.Encryptions = new Dictionary<string, CipherInfo>()
|
||||
{
|
||||
{"aes256-ctr", new CipherInfo(256, (key, iv)=>{ return new AesCipher(key, new CtrCipherMode(iv), null); }) },
|
||||
{"3des-cbc", new CipherInfo(192, (key, iv)=>{ return new TripleDesCipher(key, new CbcCipherMode(iv), null); }) },
|
||||
{"aes128-cbc", new CipherInfo(128, (key, iv)=>{ return new AesCipher(key, new CbcCipherMode(iv), null); }) },
|
||||
{"aes192-cbc", new CipherInfo(192, (key, iv)=>{ return new AesCipher(key, new CbcCipherMode(iv), null); }) },
|
||||
@@ -233,7 +234,6 @@ namespace Renci.SshNet
|
||||
////{"rijndael-cbc@lysator.liu.se", typeof(...)},
|
||||
{"aes128-ctr", new CipherInfo(128, (key, iv)=>{ return new AesCipher(key, new CtrCipherMode(iv), null); }) },
|
||||
{"aes192-ctr", new CipherInfo(192, (key, iv)=>{ return new AesCipher(key, new CtrCipherMode(iv), null); }) },
|
||||
{"aes256-ctr", new CipherInfo(256, (key, iv)=>{ return new AesCipher(key, new CtrCipherMode(iv), null); }) },
|
||||
};
|
||||
|
||||
this.HmacAlgorithms = new Dictionary<string, Func<byte[], HashAlgorithm>>()
|
||||
|
||||
@@ -388,6 +388,9 @@
|
||||
</Compile>
|
||||
<Compile Include="Shell.cs" />
|
||||
<Compile Include="Shell.NET40.cs" />
|
||||
<Compile Include="ShellStream.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="SshClient.cs" />
|
||||
<Compile Include="SshCommand.cs" />
|
||||
<Compile Include="SshCommand.NET40.cs" />
|
||||
|
||||
@@ -130,7 +130,7 @@ namespace Renci.SshNet.Security
|
||||
var compressionAlgorithmName = (from b in session.ConnectionInfo.CompressionAlgorithms.Keys
|
||||
from a in message.CompressionAlgorithmsClientToServer
|
||||
where a == b
|
||||
select a).FirstOrDefault();
|
||||
select a).LastOrDefault();
|
||||
if (string.IsNullOrEmpty(compressionAlgorithmName))
|
||||
{
|
||||
throw new SshConnectionException("Compression algorithm not found", DisconnectReason.KeyExchangeFailed);
|
||||
@@ -142,7 +142,7 @@ namespace Renci.SshNet.Security
|
||||
var decompressionAlgorithmName = (from b in session.ConnectionInfo.CompressionAlgorithms.Keys
|
||||
from a in message.CompressionAlgorithmsServerToClient
|
||||
where a == b
|
||||
select a).FirstOrDefault();
|
||||
select a).LastOrDefault();
|
||||
if (string.IsNullOrEmpty(decompressionAlgorithmName))
|
||||
{
|
||||
throw new SshConnectionException("Decompression algorithm not found", DisconnectReason.KeyExchangeFailed);
|
||||
|
||||
@@ -0,0 +1,341 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
using Renci.SshNet.Channels;
|
||||
using Renci.SshNet.Common;
|
||||
using System.Threading;
|
||||
|
||||
namespace Renci.SshNet
|
||||
{
|
||||
public class ShellStream : Stream
|
||||
{
|
||||
private readonly Session _session;
|
||||
|
||||
private ChannelSession _channel;
|
||||
|
||||
private Queue<byte> _incoming;
|
||||
|
||||
private Queue<byte> _outgoing;
|
||||
|
||||
private int _bufferSize;
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when an error occurred.
|
||||
/// </summary>
|
||||
public event EventHandler<ExceptionEventArgs> ErrorOccurred;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value that indicates whether data is available on the <see cref="ShellStream"/> to be read.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// <c>true</c> if can be read; otherwise, <c>false</c>.
|
||||
/// </value>
|
||||
public bool DataAvailable
|
||||
{
|
||||
get
|
||||
{
|
||||
lock (this._incoming)
|
||||
{
|
||||
//Monitor.Wait(this._incoming);
|
||||
var result = this._incoming.Count > 0;
|
||||
//Monitor.Pulse(this._incoming);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public EventWaitHandle DataAvailableWaitHandle { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ShellStream"/> class.
|
||||
/// </summary>
|
||||
/// <param name="session">The session.</param>
|
||||
/// <param name="terminalName">Name of the terminal.</param>
|
||||
/// <param name="columns">The columns.</param>
|
||||
/// <param name="rows">The rows.</param>
|
||||
/// <param name="width">The width.</param>
|
||||
/// <param name="height">The height.</param>
|
||||
/// <param name="terminalMode">The terminal mode.</param>
|
||||
/// <param name="bufferSize">Size of the buffer.</param>
|
||||
internal ShellStream(Session session, string terminalName, uint columns, uint rows, uint width, uint height, string terminalMode, int bufferSize)
|
||||
{
|
||||
this._session = session;
|
||||
|
||||
this._incoming = new Queue<byte>(bufferSize);
|
||||
this._outgoing = new Queue<byte>(bufferSize);
|
||||
|
||||
this.DataAvailableWaitHandle = new AutoResetEvent(false);
|
||||
|
||||
this._bufferSize = bufferSize;
|
||||
|
||||
this._channel = this._session.CreateChannel<ChannelSession>();
|
||||
this._channel.DataReceived += Channel_DataReceived;
|
||||
this._channel.Closed += Channel_Closed;
|
||||
this._session.Disconnected += Session_Disconnected;
|
||||
this._session.ErrorOccured += Session_ErrorOccured;
|
||||
|
||||
this._channel.Open();
|
||||
this._channel.SendPseudoTerminalRequest(terminalName, columns, rows, width, height, terminalMode);
|
||||
this._channel.SendShellRequest();
|
||||
}
|
||||
|
||||
#region Stream overide methods
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the current stream supports reading.
|
||||
/// </summary>
|
||||
/// <returns>true if the stream supports reading; otherwise, false.</returns>
|
||||
public override bool CanRead
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the current stream supports seeking.
|
||||
/// </summary>
|
||||
/// <returns>true if the stream supports seeking; otherwise, false.</returns>
|
||||
public override bool CanSeek
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the current stream supports writing.
|
||||
/// </summary>
|
||||
/// <returns>true if the stream supports writing; otherwise, false.</returns>
|
||||
public override bool CanWrite
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the length in bytes of the stream.
|
||||
/// </summary>
|
||||
/// <returns>A long value representing the length of the stream in bytes.</returns>
|
||||
///
|
||||
/// <exception cref="T:System.NotSupportedException">A class derived from Stream does not support seeking. </exception>
|
||||
///
|
||||
/// <exception cref="T:System.ObjectDisposedException">Methods were called after the stream was closed. </exception>
|
||||
public override long Length
|
||||
{
|
||||
get { return this._incoming.Count; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the position within the current stream.
|
||||
/// </summary>
|
||||
/// <returns>The current position within the stream.</returns>
|
||||
///
|
||||
/// <exception cref="T:System.IO.IOException">An I/O error occurs. </exception>
|
||||
///
|
||||
/// <exception cref="T:System.NotSupportedException">The stream does not support seeking. </exception>
|
||||
///
|
||||
/// <exception cref="T:System.ObjectDisposedException">Methods were called after the stream was closed. </exception>
|
||||
public override long Position
|
||||
{
|
||||
get { return 0; }
|
||||
set { throw new NotSupportedException(); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads a sequence of bytes from the current stream and advances the position within the stream by the number of bytes read.
|
||||
/// </summary>
|
||||
/// <param name="buffer">An array of bytes. When this method returns, the buffer contains the specified byte array with the values between <paramref name="offset"/> and (<paramref name="offset"/> + <paramref name="count"/> - 1) replaced by the bytes read from the current source.</param>
|
||||
/// <param name="offset">The zero-based byte offset in <paramref name="buffer"/> at which to begin storing the data read from the current stream.</param>
|
||||
/// <param name="count">The maximum number of bytes to be read from the current stream.</param>
|
||||
/// <returns>
|
||||
/// The total number of bytes read into the buffer. This can be less than the number of bytes requested if that many bytes are not currently available, or zero (0) if the end of the stream has been reached.
|
||||
/// </returns>
|
||||
/// <exception cref="T:System.ArgumentException">The sum of <paramref name="offset"/> and <paramref name="count"/> is larger than the buffer length. </exception>
|
||||
///
|
||||
/// <exception cref="T:System.ArgumentNullException">
|
||||
/// <paramref name="buffer"/> is null. </exception>
|
||||
///
|
||||
/// <exception cref="T:System.ArgumentOutOfRangeException">
|
||||
/// <paramref name="offset"/> or <paramref name="count"/> is negative. </exception>
|
||||
///
|
||||
/// <exception cref="T:System.IO.IOException">An I/O error occurs. </exception>
|
||||
///
|
||||
/// <exception cref="T:System.NotSupportedException">The stream does not support reading. </exception>
|
||||
///
|
||||
/// <exception cref="T:System.ObjectDisposedException">Methods were called after the stream was closed. </exception>
|
||||
public override int Read(byte[] buffer, int offset, int count)
|
||||
{
|
||||
var read = 0;
|
||||
|
||||
if (this._incoming.Count > 0)
|
||||
{
|
||||
lock (this._incoming)
|
||||
{
|
||||
while (this._incoming.Count < 1)
|
||||
Monitor.Wait(this._incoming);
|
||||
|
||||
for (read = 0; read < count && this._incoming.Count > 0; read++)
|
||||
{
|
||||
buffer[offset + read] = this._incoming.Dequeue();
|
||||
}
|
||||
|
||||
Monitor.Pulse(this._incoming);
|
||||
}
|
||||
}
|
||||
return read;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the position within the current stream.
|
||||
/// </summary>
|
||||
/// <param name="offset">A byte offset relative to the <paramref name="origin"/> parameter.</param>
|
||||
/// <param name="origin">A value of type <see cref="T:System.IO.SeekOrigin"/> indicating the reference point used to obtain the new position.</param>
|
||||
/// <returns>
|
||||
/// The new position within the current stream.
|
||||
/// </returns>
|
||||
/// <exception cref="T:System.IO.IOException">An I/O error occurs. </exception>
|
||||
///
|
||||
/// <exception cref="T:System.NotSupportedException">The stream does not support seeking, such as if the stream is constructed from a pipe or console output. </exception>
|
||||
///
|
||||
/// <exception cref="T:System.ObjectDisposedException">Methods were called after the stream was closed. </exception>
|
||||
public override long Seek(long offset, SeekOrigin origin)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the length of the current stream.
|
||||
/// </summary>
|
||||
/// <param name="value">The desired length of the current stream in bytes.</param>
|
||||
/// <exception cref="T:System.IO.IOException">An I/O error occurs. </exception>
|
||||
///
|
||||
/// <exception cref="T:System.NotSupportedException">The stream does not support both writing and seeking, such as if the stream is constructed from a pipe or console output. </exception>
|
||||
///
|
||||
/// <exception cref="T:System.ObjectDisposedException">Methods were called after the stream was closed. </exception>
|
||||
public override void SetLength(long value)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes a sequence of bytes to the current stream and advances the current position within this stream by the number of bytes written.
|
||||
/// </summary>
|
||||
/// <param name="buffer">An array of bytes. This method copies <paramref name="count"/> bytes from <paramref name="buffer"/> to the current stream.</param>
|
||||
/// <param name="offset">The zero-based byte offset in <paramref name="buffer"/> at which to begin copying bytes to the current stream.</param>
|
||||
/// <param name="count">The number of bytes to be written to the current stream.</param>
|
||||
/// <exception cref="T:System.ArgumentException">The sum of <paramref name="offset"/> and <paramref name="count"/> is greater than the buffer length. </exception>
|
||||
///
|
||||
/// <exception cref="T:System.ArgumentNullException">
|
||||
/// <paramref name="buffer"/> is null. </exception>
|
||||
///
|
||||
/// <exception cref="T:System.ArgumentOutOfRangeException">
|
||||
/// <paramref name="offset"/> or <paramref name="count"/> is negative. </exception>
|
||||
///
|
||||
/// <exception cref="T:System.IO.IOException">An I/O error occurs. </exception>
|
||||
///
|
||||
/// <exception cref="T:System.NotSupportedException">The stream does not support writing. </exception>
|
||||
///
|
||||
/// <exception cref="T:System.ObjectDisposedException">Methods were called after the stream was closed. </exception>
|
||||
public override void Write(byte[] buffer, int offset, int count)
|
||||
{
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
this._outgoing.Enqueue(buffer[offset + i]);
|
||||
if (this._outgoing.Count >= this._bufferSize)
|
||||
{
|
||||
this.Flush();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clears all buffers for this stream and causes any buffered data to be written to the underlying device.
|
||||
/// </summary>
|
||||
/// <exception cref="T:System.IO.IOException">An I/O error occurs. </exception>
|
||||
public override void Flush()
|
||||
{
|
||||
this._channel.SendData(this._outgoing.ToArray());
|
||||
this._outgoing.Clear();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Releases the unmanaged resources used by the <see cref="T:System.IO.Stream"/> and optionally releases the managed resources.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true to release both managed and unmanaged resources; false to release only unmanaged resources.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
base.Dispose(disposing);
|
||||
|
||||
if (this._channel.IsOpen)
|
||||
{
|
||||
this._channel.SendEof();
|
||||
|
||||
this._channel.Close();
|
||||
}
|
||||
|
||||
this._channel.DataReceived -= Channel_DataReceived;
|
||||
//this._channel.ExtendedDataReceived -= Channel_ExtendedDataReceived;
|
||||
this._channel.Closed -= Channel_Closed;
|
||||
this._session.Disconnected -= Session_Disconnected;
|
||||
this._session.ErrorOccured -= Session_ErrorOccured;
|
||||
|
||||
if (this.DataAvailableWaitHandle != null)
|
||||
{
|
||||
this.DataAvailableWaitHandle.Dispose();
|
||||
this.DataAvailableWaitHandle = null;
|
||||
}
|
||||
|
||||
|
||||
this._channel = null;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private void Channel_DataReceived(object sender, Common.ChannelDataEventArgs e)
|
||||
{
|
||||
lock (this._incoming)
|
||||
{
|
||||
// wait until the buffer isn't full
|
||||
while (this._incoming.Count >= this._bufferSize)
|
||||
Monitor.Wait(this._incoming);
|
||||
|
||||
for (int i = 0; i < e.Data.Length; i++)
|
||||
{
|
||||
this._incoming.Enqueue(e.Data[i]);
|
||||
}
|
||||
|
||||
Monitor.Pulse(this._incoming); // signal that write has occurred
|
||||
}
|
||||
|
||||
this.DataAvailableWaitHandle.Set();
|
||||
|
||||
}
|
||||
|
||||
private void Channel_Closed(object sender, Common.ChannelEventArgs e)
|
||||
{
|
||||
this.Dispose();
|
||||
}
|
||||
|
||||
private void Session_Disconnected(object sender, System.EventArgs e)
|
||||
{
|
||||
// If channel is open then close it to cause Channel_Closed method to be called
|
||||
if (this._channel != null && this._channel.IsOpen)
|
||||
{
|
||||
this._channel.SendEof();
|
||||
|
||||
this._channel.Close();
|
||||
}
|
||||
}
|
||||
|
||||
private void Session_ErrorOccured(object sender, ExceptionEventArgs e)
|
||||
{
|
||||
this.RaiseError(e);
|
||||
}
|
||||
|
||||
private void RaiseError(ExceptionEventArgs e)
|
||||
{
|
||||
if (this.ErrorOccurred != null)
|
||||
{
|
||||
this.ErrorOccurred(this, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,7 @@ namespace Renci.SshNet
|
||||
private List<ForwardedPort> _forwardedPorts = new List<ForwardedPort>();
|
||||
|
||||
private bool _disposeConnectionInfo;
|
||||
|
||||
|
||||
private Stream _inputStream;
|
||||
|
||||
/// <summary>
|
||||
@@ -54,7 +54,7 @@ namespace Renci.SshNet
|
||||
/// <exception cref="ArgumentNullException"><paramref name="password"/> is null.</exception>
|
||||
/// <exception cref="ArgumentException"><paramref name="host"/> is invalid, or <paramref name="username"/> is null or contains whitespace characters.</exception>
|
||||
/// <exception cref="ArgumentOutOfRangeException"><paramref name="port"/> is not within <see cref="System.Net.IPEndPoint.MinPort"/> and <see cref="System.Net.IPEndPoint.MaxPort"/>.</exception>
|
||||
[SuppressMessage("Microsoft.Reliability", "CA2000:DisposeObjectsBeforeLosingScope", Justification="Disposed in Dispose(bool) method.")]
|
||||
[SuppressMessage("Microsoft.Reliability", "CA2000:DisposeObjectsBeforeLosingScope", Justification = "Disposed in Dispose(bool) method.")]
|
||||
public SshClient(string host, int port, string username, string password)
|
||||
: this(new PasswordConnectionInfo(host, port, username, password))
|
||||
{
|
||||
@@ -123,7 +123,7 @@ namespace Renci.SshNet
|
||||
/// Adds the forwarded port.
|
||||
/// </summary>
|
||||
/// <param name="port">The port.</param>
|
||||
public void AddForwardedPort(ForwardedPort port)
|
||||
public void AddForwardedPort(ForwardedPort port)
|
||||
{
|
||||
// Ensure that connection is established.
|
||||
this.EnsureConnection();
|
||||
@@ -188,7 +188,7 @@ namespace Renci.SshNet
|
||||
/// <exception cref="Renci.SshNet.Common.SshException">Invalid Operation - An existing channel was used to execute this command.</exception>
|
||||
/// <exception cref="InvalidOperationException">Asynchronous operation is already in progress.</exception>
|
||||
public SshCommand RunCommand(string commandText)
|
||||
{
|
||||
{
|
||||
var cmd = this.CreateCommand(commandText);
|
||||
cmd.Execute();
|
||||
return cmd;
|
||||
@@ -261,7 +261,7 @@ namespace Renci.SshNet
|
||||
/// <param name="terminalMode">The terminal mode.</param>
|
||||
/// <param name="bufferSize">Size of the internal read buffer.</param>
|
||||
/// <returns>Returns a representation of a <see cref="Shell"/> object.</returns>
|
||||
public Shell CreateShell(Encoding encoding, string input, Stream output, Stream extendedOutput, string terminalName, uint columns, uint rows, uint width , uint height , string terminalMode, int bufferSize)
|
||||
public Shell CreateShell(Encoding encoding, string input, Stream output, Stream extendedOutput, string terminalName, uint columns, uint rows, uint width, uint height, string terminalMode, int bufferSize)
|
||||
{
|
||||
// Ensure that connection is established.
|
||||
this.EnsureConnection();
|
||||
@@ -307,6 +307,26 @@ namespace Renci.SshNet
|
||||
return this.CreateShell(encoding, input, output, extendedOutput, string.Empty, 0, 0, 0, 0, string.Empty, 1024);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates the shell stream.
|
||||
/// </summary>
|
||||
/// <param name="terminalName">Name of the terminal.</param>
|
||||
/// <param name="columns">The columns.</param>
|
||||
/// <param name="rows">The rows.</param>
|
||||
/// <param name="width">The width.</param>
|
||||
/// <param name="height">The height.</param>
|
||||
/// <param name="terminalMode">The terminal mode.</param>
|
||||
/// <param name="bufferSize">Size of the buffer.</param>
|
||||
/// <returns></returns>
|
||||
public ShellStream CreateShellStream(string terminalName, uint columns, uint rows, uint width, uint height, string terminalMode, int bufferSize)
|
||||
{
|
||||
// Ensure that connection is established.
|
||||
this.EnsureConnection();
|
||||
|
||||
return new ShellStream(this.Session, terminalName, columns, rows, width, height, terminalMode, bufferSize);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Releases unmanaged and - optionally - managed resources
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user