diff --git a/Renci.SshClient/Renci.SshClient.Tests/ConnectionData.cs b/Renci.SshClient/Renci.SshClient.Tests/ConnectionData.cs index d6eca877..c54e0c7e 100644 --- a/Renci.SshClient/Renci.SshClient.Tests/ConnectionData.cs +++ b/Renci.SshClient/Renci.SshClient.Tests/ConnectionData.cs @@ -3,16 +3,16 @@ namespace Renci.SshClient.Tests { public static class ConnectionData { - public static string Host { get { return "you host here"; } } + public static string Host { get { return "152.54.8.155"; } } public static int Port { get { return 22; } } - public static string Username { get { return "username"; } } + public static string Username { get { return "oleg"; } } - public static string Password { get { return "password@"; } } + public static string Password { get { return "Maya1kap@"; } } - public static string RsaKeyFilePath { get { return @"path to rsa key file"; } } + public static string RsaKeyFilePath { get { return @"H:\My Documents\SSHKeys\oleg-test4.rsa.key"; } } - public static string DssKeyFilePath { get { return @"path to dss key file"; } } + public static string DssKeyFilePath { get { return @"H:\My Documents\SSHKeys\oleg-test4.dsa.key"; } } } } diff --git a/Renci.SshClient/Renci.SshClient.Tests/PortForwardingTest.cs b/Renci.SshClient/Renci.SshClient.Tests/PortForwardingTest.cs index cd6325b2..94c6f581 100644 --- a/Renci.SshClient/Renci.SshClient.Tests/PortForwardingTest.cs +++ b/Renci.SshClient/Renci.SshClient.Tests/PortForwardingTest.cs @@ -64,7 +64,7 @@ namespace Renci.SshClient.Tests { var client = CreateShellUsingPassword(); client.Connect(); - var port1 = client.AddForwardedPort(8082, "www.renci.org", 80); + var port1 = client.AddForwardedPort(8084, "www.renci.org", 80); port1.Exception += delegate(object sender, ExceptionEventArgs e) { Assert.Fail(e.Exception.ToString()); @@ -79,7 +79,7 @@ namespace Renci.SshClient.Tests (counter) => { var start = DateTime.Now; - var req = HttpWebRequest.Create("http://localhost:8082"); + var req = HttpWebRequest.Create("http://localhost:8084"); using (var response = req.GetResponse()) { diff --git a/Renci.SshClient/Renci.SshClient/Channels/Channel.cs b/Renci.SshClient/Renci.SshClient/Channels/Channel.cs index c09789b3..3507d69f 100644 --- a/Renci.SshClient/Renci.SshClient/Channels/Channel.cs +++ b/Renci.SshClient/Renci.SshClient/Channels/Channel.cs @@ -20,6 +20,8 @@ namespace Renci.SshClient.Channels /// private bool _closeMessageSent = false; + private Session _session; + public abstract ChannelTypes ChannelType { get; } public uint LocalChannelNumber { get; private set; } @@ -34,7 +36,18 @@ namespace Renci.SshClient.Channels public bool IsOpen { get; private set; } - protected Session Session { get; private set; } + protected bool IsConnected + { + get { return this._session.IsConnected; } + } + + protected ConnectionInfo ConnectionInfo + { + get + { + return this._session.ConnectionInfo; + } + } internal Channel() { @@ -45,34 +58,34 @@ namespace Renci.SshClient.Channels this._initialWindowSize = windowSize; this._maximumPacketSize = Math.Max(packetSize, 0x8000); // Ensure minimum maximum packet size of 0x8000 bytes - this.Session = session; + this._session = session; this.LocalWindowSize = this._initialWindowSize; // Initial window size this.PacketSize = this._maximumPacketSize; // Maximum packet size this.LocalChannelNumber = session.NextChannelNumber; this.RemoteChannelNumber = serverChannelNumber; - this.Session.RegisterMessageType(MessageTypes.ChannelOpenConfirmation); - this.Session.RegisterMessageType(MessageTypes.ChannelOpenFailure); - this.Session.RegisterMessageType(MessageTypes.ChannelWindowAdjust); - this.Session.RegisterMessageType(MessageTypes.ChannelExtendedData); - this.Session.RegisterMessageType(MessageTypes.ChannelRequest); - this.Session.RegisterMessageType(MessageTypes.ChannelSuccess); - this.Session.RegisterMessageType(MessageTypes.ChannelData); - this.Session.RegisterMessageType(MessageTypes.ChannelEof); - this.Session.RegisterMessageType(MessageTypes.ChannelClose); + this._session.RegisterMessageType(MessageTypes.ChannelOpenConfirmation); + this._session.RegisterMessageType(MessageTypes.ChannelOpenFailure); + this._session.RegisterMessageType(MessageTypes.ChannelWindowAdjust); + this._session.RegisterMessageType(MessageTypes.ChannelExtendedData); + this._session.RegisterMessageType(MessageTypes.ChannelRequest); + this._session.RegisterMessageType(MessageTypes.ChannelSuccess); + this._session.RegisterMessageType(MessageTypes.ChannelData); + this._session.RegisterMessageType(MessageTypes.ChannelEof); + this._session.RegisterMessageType(MessageTypes.ChannelClose); - this.Session.ChannelOpen += OnChannelOpen; - this.Session.ChannelOpenConfirmation += OnChannelOpenConfirmation; - this.Session.ChannelOpenFailure += OnChannelOpenFailure; - this.Session.ChannelWindowAdjust += OnChannelWindowAdjust; - this.Session.ChannelData += OnChannelData; - this.Session.ChannelExtendedData += OnChannelExtendedData; - this.Session.ChannelEof += OnChannelEof; - this.Session.ChannelClose += OnChannelClose; - this.Session.ChannelRequest += OnChannelRequest; - this.Session.ChannelSuccess += OnChannelSuccess; - this.Session.ChannelFailure += OnChannelFailure; + this._session.ChannelOpen += OnChannelOpen; + this._session.ChannelOpenConfirmation += OnChannelOpenConfirmation; + this._session.ChannelOpenFailure += OnChannelOpenFailure; + this._session.ChannelWindowAdjust += OnChannelWindowAdjust; + this._session.ChannelData += OnChannelData; + this._session.ChannelExtendedData += OnChannelExtendedData; + this._session.ChannelEof += OnChannelEof; + this._session.ChannelClose += OnChannelClose; + this._session.ChannelRequest += OnChannelRequest; + this._session.ChannelSuccess += OnChannelSuccess; + this._session.ChannelFailure += OnChannelFailure; } @@ -83,7 +96,7 @@ namespace Renci.SshClient.Channels this.SendChannelCloseMessage(); // Wait for channel to be closed - this.Session.WaitHandle(this._channelClosedWaitHandle); + this._session.WaitHandle(this._channelClosedWaitHandle); } this.CloseCleanup(); @@ -151,7 +164,7 @@ namespace Renci.SshClient.Channels protected void SendMessage(Message message) { - this.Session.SendMessage(message); + this._session.SendMessage(message); } protected void SendMessage(ChannelDataMessage message) @@ -159,11 +172,11 @@ namespace Renci.SshClient.Channels if (this.ServerWindowSize < 1) { // Wait for window to be adjust - this.Session.WaitHandle(this._channelWindowAdjustWaitHandle); + this._session.WaitHandle(this._channelWindowAdjustWaitHandle); } this.ServerWindowSize -= (uint)message.Data.Length; - this.Session.SendMessage(message); + this._session.SendMessage(message); } protected void SendMessage(ChannelExtendedDataMessage message) @@ -171,11 +184,11 @@ namespace Renci.SshClient.Channels if (this.ServerWindowSize < 1) { // Wait for window to be adjust - this.Session.WaitHandle(this._channelWindowAdjustWaitHandle); + this._session.WaitHandle(this._channelWindowAdjustWaitHandle); } this.ServerWindowSize -= (uint)message.Data.Length; - this.Session.SendMessage(message); + this._session.SendMessage(message); } protected void CloseCleanup() @@ -187,6 +200,11 @@ namespace Renci.SshClient.Channels this.SendChannelCloseMessage(); } + protected void WaitHandle(WaitHandle waitHandle) + { + this._session.WaitHandle(waitHandle); + } + #region Channel message event handlers private void OnChannelOpen(object sender, MessageEventArgs e) diff --git a/Renci.SshClient/Renci.SshClient/Channels/ChannelDirectTcpip.cs b/Renci.SshClient/Renci.SshClient/Channels/ChannelDirectTcpip.cs index 2517838b..53d6a5d2 100644 --- a/Renci.SshClient/Renci.SshClient/Channels/ChannelDirectTcpip.cs +++ b/Renci.SshClient/Renci.SshClient/Channels/ChannelDirectTcpip.cs @@ -36,7 +36,7 @@ namespace Renci.SshClient.Channels IPEndPoint ep = socket.RemoteEndPoint as IPEndPoint; - if (!this.Session.IsConnected) + if (!this.IsConnected) { throw new SshException("Session is not connected."); } @@ -55,7 +55,7 @@ namespace Renci.SshClient.Channels }); // Wait for channel to open - this.Session.WaitHandle(this._channelOpen); + this.WaitHandle(this._channelOpen); // Start reading data from the port and send to channel EventWaitHandle readerTaskError = new AutoResetEvent(false); @@ -66,7 +66,7 @@ namespace Renci.SshClient.Channels { var buffer = new byte[this.PacketSize - 9]; - while (this._socket.Connected || this.Session.IsConnected) + while (this._socket.Connected || this.IsConnected) { try { @@ -112,7 +112,7 @@ namespace Renci.SshClient.Channels // Channel was open and we MUST receive EOF notification, // data transfer can take longer then connection specified timeout - WaitHandle.WaitAny(new WaitHandle[] { this._channelEof, readerTaskError }); + System.Threading.WaitHandle.WaitAny(new WaitHandle[] { this._channelEof, readerTaskError }); this._socket.Close(); diff --git a/Renci.SshClient/Renci.SshClient/Channels/ChannelForwardedTcpip.cs b/Renci.SshClient/Renci.SshClient/Channels/ChannelForwardedTcpip.cs index 27d09fc4..f0ebbd9a 100644 --- a/Renci.SshClient/Renci.SshClient/Channels/ChannelForwardedTcpip.cs +++ b/Renci.SshClient/Renci.SshClient/Channels/ChannelForwardedTcpip.cs @@ -28,7 +28,7 @@ namespace Renci.SshClient.Channels this.ServerWindowSize = this.LocalWindowSize; - if (!this.Session.IsConnected) + if (!this.IsConnected) { throw new SshException("Session is not connected."); } diff --git a/Renci.SshClient/Renci.SshClient/Channels/ChannelSession.cs b/Renci.SshClient/Renci.SshClient/Channels/ChannelSession.cs index 8163f757..3a0a6f8e 100644 --- a/Renci.SshClient/Renci.SshClient/Channels/ChannelSession.cs +++ b/Renci.SshClient/Renci.SshClient/Channels/ChannelSession.cs @@ -44,10 +44,10 @@ namespace Renci.SshClient.Channels if (!this.IsOpen) { // Try to opend channel several times - while (this._failedOpenAttempts < this.Session.ConnectionInfo.RetryAttempts && !this.IsOpen) + while (this._failedOpenAttempts < this.ConnectionInfo.RetryAttempts && !this.IsOpen) { this.SendChannelOpenMessage(); - this.Session.WaitHandle(this._channelOpenResponseWaitHandle); + this.WaitHandle(this._channelOpenResponseWaitHandle); } if (!this.IsOpen) diff --git a/Renci.SshClient/Renci.SshClient/Channels/ChannelSessionExec.cs b/Renci.SshClient/Renci.SshClient/Channels/ChannelSessionExec.cs index 4581ec63..baf94501 100644 --- a/Renci.SshClient/Renci.SshClient/Channels/ChannelSessionExec.cs +++ b/Renci.SshClient/Renci.SshClient/Channels/ChannelSessionExec.cs @@ -72,7 +72,7 @@ namespace Renci.SshClient.Channels } // Make sure that operation completed if not wait for it to finish - this.Session.WaitHandle(this._asyncResult.AsyncWaitHandle); + this.WaitHandle(this._asyncResult.AsyncWaitHandle); this.Close(); diff --git a/Renci.SshClient/Renci.SshClient/Session.cs b/Renci.SshClient/Renci.SshClient/Session.cs index 535798c2..cae395e0 100644 --- a/Renci.SshClient/Renci.SshClient/Session.cs +++ b/Renci.SshClient/Renci.SshClient/Session.cs @@ -897,7 +897,7 @@ namespace Renci.SshClient } else { - this._socket.Disconnect(true); + this._socket.Disconnect(false); throw new SshException("An established connection was aborted by the software in your host machine."); } } diff --git a/Renci.SshClient/Renci.SshClient/SshClient.cs b/Renci.SshClient/Renci.SshClient/SshClient.cs index 361974bc..05695ef2 100644 --- a/Renci.SshClient/Renci.SshClient/SshClient.cs +++ b/Renci.SshClient/Renci.SshClient/SshClient.cs @@ -102,6 +102,7 @@ namespace Renci.SshClient public void Connect() { + this._session = new Session(this._connectionInfo); this._session.Connect(); }