mirror of
https://github.com/sshnet/SSH.NET.git
synced 2026-09-10 09:15:47 +00:00
Make some classes public instead of internal
Add SshBasClient class and make SshClient and SftpClient to inherit from it
This commit is contained in:
@@ -3,13 +3,13 @@ namespace Renci.SshClient.Tests
|
||||
{
|
||||
public static class ConnectionData
|
||||
{
|
||||
public static string Host { get { return "server"; } }
|
||||
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 "Maya2kap#"; } }
|
||||
|
||||
public static string RsaKeyFilePath { get { return @"RSA key path"; } }
|
||||
|
||||
|
||||
@@ -108,8 +108,9 @@ namespace Renci.SshClient.Tests
|
||||
Assert.Fail(e.Exception.ToString());
|
||||
};
|
||||
port1.Start();
|
||||
var boundport = port1.BoundPort;
|
||||
|
||||
System.Threading.Tasks.Parallel.For(0, 100,
|
||||
System.Threading.Tasks.Parallel.For(0, 5,
|
||||
//new ParallelOptions
|
||||
//{
|
||||
// MaxDegreeOfParallelism = 1,
|
||||
@@ -120,10 +121,10 @@ namespace Renci.SshClient.Tests
|
||||
try
|
||||
{
|
||||
|
||||
var cmd = client.CreateCommand("wget -O- http://localhost:8082");
|
||||
var cmd = client.CreateCommand(string.Format("wget -O- http://localhost:{0}", boundport));
|
||||
var result = cmd.Execute();
|
||||
var end = DateTime.Now;
|
||||
Debug.Write(string.Format("Length: {0}", result.Length));
|
||||
Debug.WriteLine(string.Format("Length: {0}", result.Length));
|
||||
}
|
||||
catch (Exception exp)
|
||||
{
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
using Renci.SshClient.Security;
|
||||
namespace Renci.SshClient.Compression
|
||||
{
|
||||
internal abstract class Compressor : Algorithm
|
||||
public abstract class Compressor : Algorithm
|
||||
{
|
||||
protected Session Session { get; private set; }
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace Renci.SshClient.Messages.Authentication
|
||||
{
|
||||
internal class BannerMessage : Message
|
||||
public class BannerMessage : Message
|
||||
{
|
||||
public override MessageTypes MessageType
|
||||
{
|
||||
|
||||
@@ -3,7 +3,7 @@ using System.Collections.Generic;
|
||||
|
||||
namespace Renci.SshClient.Messages.Authentication
|
||||
{
|
||||
internal class FailureMessage : Message
|
||||
public class FailureMessage : Message
|
||||
{
|
||||
public override MessageTypes MessageType
|
||||
{
|
||||
|
||||
@@ -3,7 +3,7 @@ using System.Text;
|
||||
|
||||
namespace Renci.SshClient.Messages.Authentication
|
||||
{
|
||||
internal class RequestMessage : Message
|
||||
public class RequestMessage : Message
|
||||
{
|
||||
public override MessageTypes MessageType
|
||||
{
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
|
||||
namespace Renci.SshClient.Messages.Authentication
|
||||
{
|
||||
internal class SuccessMessage : Message
|
||||
public class SuccessMessage : Message
|
||||
{
|
||||
public override MessageTypes MessageType
|
||||
{
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
|
||||
namespace Renci.SshClient.Messages.Connection
|
||||
{
|
||||
internal class ChannelCloseMessage : ChannelMessage
|
||||
public class ChannelCloseMessage : ChannelMessage
|
||||
{
|
||||
public override MessageTypes MessageType
|
||||
{
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
namespace Renci.SshClient.Messages.Connection
|
||||
{
|
||||
internal class ChannelDataMessage : ChannelMessage
|
||||
public class ChannelDataMessage : ChannelMessage
|
||||
{
|
||||
public override MessageTypes MessageType
|
||||
{
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
namespace Renci.SshClient.Messages.Connection
|
||||
{
|
||||
internal class ChannelEofMessage : ChannelMessage
|
||||
public class ChannelEofMessage : ChannelMessage
|
||||
{
|
||||
public override MessageTypes MessageType
|
||||
{
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
|
||||
namespace Renci.SshClient.Messages.Connection
|
||||
{
|
||||
internal class ChannelExtendedDataMessage : ChannelMessage
|
||||
public class ChannelExtendedDataMessage : ChannelMessage
|
||||
{
|
||||
public override MessageTypes MessageType
|
||||
{
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
|
||||
namespace Renci.SshClient.Messages.Connection
|
||||
{
|
||||
internal class ChannelFailureMessage : ChannelMessage
|
||||
public class ChannelFailureMessage : ChannelMessage
|
||||
{
|
||||
public override MessageTypes MessageType
|
||||
{
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
|
||||
namespace Renci.SshClient.Messages.Connection
|
||||
{
|
||||
internal abstract class ChannelMessage : Message
|
||||
public abstract class ChannelMessage : Message
|
||||
{
|
||||
public uint LocalChannelNumber { get; set; }
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace Renci.SshClient.Messages.Connection
|
||||
{
|
||||
internal abstract class ChannelOpenInfo : SshData
|
||||
public abstract class ChannelOpenInfo : SshData
|
||||
{
|
||||
public abstract string ChannelType { get; }
|
||||
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace Renci.SshClient.Messages.Connection
|
||||
{
|
||||
internal class ChannelOpenMessage : ChannelMessage
|
||||
public class ChannelOpenMessage : ChannelMessage
|
||||
{
|
||||
public override MessageTypes MessageType
|
||||
{
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
namespace Renci.SshClient.Messages.Connection
|
||||
{
|
||||
internal class ChannelOpenConfirmationMessage : ChannelMessage
|
||||
public class ChannelOpenConfirmationMessage : ChannelMessage
|
||||
{
|
||||
public override MessageTypes MessageType
|
||||
{
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
namespace Renci.SshClient.Messages.Connection
|
||||
{
|
||||
internal class ChannelOpenFailureMessage : ChannelMessage
|
||||
public class ChannelOpenFailureMessage : ChannelMessage
|
||||
{
|
||||
public override MessageTypes MessageType
|
||||
{
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace Renci.SshClient.Messages.Connection
|
||||
{
|
||||
internal class ChannelRequestMessage : ChannelMessage
|
||||
public class ChannelRequestMessage : ChannelMessage
|
||||
{
|
||||
public override MessageTypes MessageType
|
||||
{
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace Renci.SshClient.Messages.Connection
|
||||
{
|
||||
internal abstract class RequestInfo : SshData
|
||||
public abstract class RequestInfo : SshData
|
||||
{
|
||||
public abstract string RequestName { get; }
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
|
||||
namespace Renci.SshClient.Messages.Connection
|
||||
{
|
||||
internal class ChannelSuccessMessage : ChannelMessage
|
||||
public class ChannelSuccessMessage : ChannelMessage
|
||||
{
|
||||
public override MessageTypes MessageType
|
||||
{
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
|
||||
namespace Renci.SshClient.Messages.Connection
|
||||
{
|
||||
internal class ChannelWindowAdjustMessage : ChannelMessage
|
||||
public class ChannelWindowAdjustMessage : ChannelMessage
|
||||
{
|
||||
public override MessageTypes MessageType
|
||||
{
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
|
||||
using System;
|
||||
using System;
|
||||
|
||||
namespace Renci.SshClient.Messages.Connection
|
||||
{
|
||||
internal class GlobalRequestMessage : Message
|
||||
public class GlobalRequestMessage : Message
|
||||
{
|
||||
public GlobalRequestNames RequestName { get; set; }
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
namespace Renci.SshClient.Messages.Connection
|
||||
{
|
||||
internal enum GlobalRequestNames
|
||||
public enum GlobalRequestNames
|
||||
{
|
||||
/// <summary>
|
||||
/// tcpip-forward
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
|
||||
namespace Renci.SshClient.Messages.Connection
|
||||
{
|
||||
internal class RequestFailureMessage : Message
|
||||
public class RequestFailureMessage : Message
|
||||
{
|
||||
public override MessageTypes MessageType
|
||||
{
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
|
||||
namespace Renci.SshClient.Messages.Connection
|
||||
{
|
||||
internal class RequestSuccessMessage : Message
|
||||
public class RequestSuccessMessage : Message
|
||||
{
|
||||
public uint? BoundPort { get; set; }
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
namespace Renci.SshClient.Messages
|
||||
{
|
||||
internal enum ServiceNames
|
||||
public enum ServiceNames
|
||||
{
|
||||
/// <summary>
|
||||
/// ssh-userauth
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
|
||||
namespace Renci.SshClient.Messages.Transport
|
||||
{
|
||||
internal class DebugMessage : Message
|
||||
public class DebugMessage : Message
|
||||
{
|
||||
public bool IsAlwaysDisplay { get; set; }
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace Renci.SshClient.Messages.Transport
|
||||
{
|
||||
internal class DisconnectMessage : Message
|
||||
public class DisconnectMessage : Message
|
||||
{
|
||||
public override MessageTypes MessageType
|
||||
{
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
|
||||
namespace Renci.SshClient.Messages.Transport
|
||||
{
|
||||
internal class IgnoreMessage : Message
|
||||
public class IgnoreMessage : Message
|
||||
{
|
||||
public string Data { get; set; }
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ using System.Security.Cryptography;
|
||||
|
||||
namespace Renci.SshClient.Messages.Transport
|
||||
{
|
||||
internal class KeyExchangeInitMessage : Message
|
||||
public class KeyExchangeInitMessage : Message
|
||||
{
|
||||
private static RNGCryptoServiceProvider _randomizer = new System.Security.Cryptography.RNGCryptoServiceProvider();
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
namespace Renci.SshClient.Messages.Transport
|
||||
{
|
||||
internal class NewKeysMessage : Message
|
||||
public class NewKeysMessage : Message
|
||||
{
|
||||
public override MessageTypes MessageType
|
||||
{
|
||||
|
||||
@@ -5,7 +5,7 @@ namespace Renci.SshClient.Messages.Transport
|
||||
/// <summary>
|
||||
/// SSH_MSG_SERVICE_ACCEPT
|
||||
/// </summary>
|
||||
internal class ServiceAcceptMessage : Message
|
||||
public class ServiceAcceptMessage : Message
|
||||
{
|
||||
public override MessageTypes MessageType
|
||||
{
|
||||
|
||||
@@ -5,7 +5,7 @@ namespace Renci.SshClient.Messages.Transport
|
||||
/// <summary>
|
||||
/// Contains SSH_MSG_SERVICE_REQUEST message information
|
||||
/// </summary>
|
||||
internal class ServiceRequestMessage : Message
|
||||
public class ServiceRequestMessage : Message
|
||||
{
|
||||
public override MessageTypes MessageType
|
||||
{
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
|
||||
namespace Renci.SshClient.Messages.Transport
|
||||
{
|
||||
internal class UnimplementedMessage : Message
|
||||
public class UnimplementedMessage : Message
|
||||
{
|
||||
public override MessageTypes MessageType
|
||||
{
|
||||
|
||||
@@ -98,6 +98,7 @@
|
||||
<Compile Include="Sftp\SftpFileAttributes.cs" />
|
||||
<Compile Include="Sftp\SftpSession.cs" />
|
||||
<Compile Include="Sftp\UploadFileCommand.cs" />
|
||||
<Compile Include="SshBaseClient.cs" />
|
||||
<Compile Include="SshCommand.cs" />
|
||||
<Compile Include="MessageEventArgs.cs" />
|
||||
<Compile Include="ChannelAsyncResult.cs" />
|
||||
|
||||
@@ -3,7 +3,7 @@ using System.Linq;
|
||||
|
||||
namespace Renci.SshClient.Security
|
||||
{
|
||||
internal abstract class Cipher
|
||||
public abstract class Cipher
|
||||
{
|
||||
public abstract string Name { get; }
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ using Renci.SshClient.Security;
|
||||
|
||||
namespace Renci.SshClient
|
||||
{
|
||||
internal class Session : IDisposable
|
||||
public class Session : IDisposable
|
||||
{
|
||||
protected const int MAXIMUM_PACKET_SIZE = 35000;
|
||||
|
||||
@@ -233,137 +233,137 @@ namespace Renci.SshClient
|
||||
/// <summary>
|
||||
/// Occurs when <see cref="DisconnectMessage"/> message received
|
||||
/// </summary>
|
||||
public event EventHandler<MessageEventArgs<DisconnectMessage>> DisconnectReceived;
|
||||
internal event EventHandler<MessageEventArgs<DisconnectMessage>> DisconnectReceived;
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when <see cref="IgnoreMessage"/> message received
|
||||
/// </summary>
|
||||
public event EventHandler<MessageEventArgs<IgnoreMessage>> IgnoreReceived;
|
||||
internal event EventHandler<MessageEventArgs<IgnoreMessage>> IgnoreReceived;
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when <see cref="UnimplementedMessage"/> message received
|
||||
/// </summary>
|
||||
public event EventHandler<MessageEventArgs<UnimplementedMessage>> UnimplementedReceived;
|
||||
internal event EventHandler<MessageEventArgs<UnimplementedMessage>> UnimplementedReceived;
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when <see cref="DebugMessage"/> message received
|
||||
/// </summary>
|
||||
public event EventHandler<MessageEventArgs<DebugMessage>> DebugReceived;
|
||||
internal event EventHandler<MessageEventArgs<DebugMessage>> DebugReceived;
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when <see cref="ServiceRequestMessage"/> message received
|
||||
/// </summary>
|
||||
public event EventHandler<MessageEventArgs<ServiceRequestMessage>> ServiceRequestReceived;
|
||||
internal event EventHandler<MessageEventArgs<ServiceRequestMessage>> ServiceRequestReceived;
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when <see cref="ServiceAcceptMessage"/> message received
|
||||
/// </summary>
|
||||
public event EventHandler<MessageEventArgs<ServiceAcceptMessage>> ServiceAcceptReceived;
|
||||
internal event EventHandler<MessageEventArgs<ServiceAcceptMessage>> ServiceAcceptReceived;
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when <see cref="KeyExchangeInitMessage"/> message received
|
||||
/// </summary>
|
||||
public event EventHandler<MessageEventArgs<KeyExchangeInitMessage>> KeyExchangeInitReceived;
|
||||
internal event EventHandler<MessageEventArgs<KeyExchangeInitMessage>> KeyExchangeInitReceived;
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when <see cref="NewKeysMessage"/> message received
|
||||
/// </summary>
|
||||
public event EventHandler<MessageEventArgs<NewKeysMessage>> NewKeysReceived;
|
||||
internal event EventHandler<MessageEventArgs<NewKeysMessage>> NewKeysReceived;
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when <see cref="RequestMessage"/> message received
|
||||
/// </summary>
|
||||
public event EventHandler<MessageEventArgs<RequestMessage>> UserAuthenticationRequestReceived;
|
||||
internal event EventHandler<MessageEventArgs<RequestMessage>> UserAuthenticationRequestReceived;
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when <see cref="FailureMessage"/> message received
|
||||
/// </summary>
|
||||
public event EventHandler<MessageEventArgs<FailureMessage>> UserAuthenticationFailureReceived;
|
||||
internal event EventHandler<MessageEventArgs<FailureMessage>> UserAuthenticationFailureReceived;
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when <see cref="SuccessMessage"/> message received
|
||||
/// </summary>
|
||||
public event EventHandler<MessageEventArgs<SuccessMessage>> UserAuthenticationSuccessReceived;
|
||||
internal event EventHandler<MessageEventArgs<SuccessMessage>> UserAuthenticationSuccessReceived;
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when <see cref="BannerMessage"/> message received
|
||||
/// </summary>
|
||||
public event EventHandler<MessageEventArgs<BannerMessage>> UserAuthenticationBannerReceived;
|
||||
internal event EventHandler<MessageEventArgs<BannerMessage>> UserAuthenticationBannerReceived;
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when <see cref="GlobalRequestMessage"/> message received
|
||||
/// </summary>
|
||||
public event EventHandler<MessageEventArgs<GlobalRequestMessage>> GlobalRequestReceived;
|
||||
internal event EventHandler<MessageEventArgs<GlobalRequestMessage>> GlobalRequestReceived;
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when <see cref="RequestSuccessMessage"/> message received
|
||||
/// </summary>
|
||||
public event EventHandler<MessageEventArgs<RequestSuccessMessage>> RequestSuccessReceived;
|
||||
internal event EventHandler<MessageEventArgs<RequestSuccessMessage>> RequestSuccessReceived;
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when <see cref="RequestFailureMessage"/> message received
|
||||
/// </summary>
|
||||
public event EventHandler<MessageEventArgs<RequestFailureMessage>> RequestFailureReceived;
|
||||
internal event EventHandler<MessageEventArgs<RequestFailureMessage>> RequestFailureReceived;
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when <see cref="ChannelOpenMessage"/> message received
|
||||
/// </summary>
|
||||
public event EventHandler<MessageEventArgs<ChannelOpenMessage>> ChannelOpenReceived;
|
||||
internal event EventHandler<MessageEventArgs<ChannelOpenMessage>> ChannelOpenReceived;
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when <see cref="ChannelOpenConfirmationMessage"/> message received
|
||||
/// </summary>
|
||||
public event EventHandler<MessageEventArgs<ChannelOpenConfirmationMessage>> ChannelOpenConfirmationReceived;
|
||||
internal event EventHandler<MessageEventArgs<ChannelOpenConfirmationMessage>> ChannelOpenConfirmationReceived;
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when <see cref="ChannelOpenFailureMessage"/> message received
|
||||
/// </summary>
|
||||
public event EventHandler<MessageEventArgs<ChannelOpenFailureMessage>> ChannelOpenFailureReceived;
|
||||
internal event EventHandler<MessageEventArgs<ChannelOpenFailureMessage>> ChannelOpenFailureReceived;
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when <see cref="ChannelWindowAdjustMessage"/> message received
|
||||
/// </summary>
|
||||
public event EventHandler<MessageEventArgs<ChannelWindowAdjustMessage>> ChannelWindowAdjustReceived;
|
||||
internal event EventHandler<MessageEventArgs<ChannelWindowAdjustMessage>> ChannelWindowAdjustReceived;
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when <see cref="ChannelDataMessage"/> message received
|
||||
/// </summary>
|
||||
public event EventHandler<MessageEventArgs<ChannelDataMessage>> ChannelDataReceived;
|
||||
internal event EventHandler<MessageEventArgs<ChannelDataMessage>> ChannelDataReceived;
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when <see cref="ChannelExtendedDataMessage"/> message received
|
||||
/// </summary>
|
||||
public event EventHandler<MessageEventArgs<ChannelExtendedDataMessage>> ChannelExtendedDataReceived;
|
||||
internal event EventHandler<MessageEventArgs<ChannelExtendedDataMessage>> ChannelExtendedDataReceived;
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when <see cref="ChannelEofMessage"/> message received
|
||||
/// </summary>
|
||||
public event EventHandler<MessageEventArgs<ChannelEofMessage>> ChannelEofReceived;
|
||||
internal event EventHandler<MessageEventArgs<ChannelEofMessage>> ChannelEofReceived;
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when <see cref="ChannelCloseMessage"/> message received
|
||||
/// </summary>
|
||||
public event EventHandler<MessageEventArgs<ChannelCloseMessage>> ChannelCloseReceived;
|
||||
internal event EventHandler<MessageEventArgs<ChannelCloseMessage>> ChannelCloseReceived;
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when <see cref="ChannelRequestMessage"/> message received
|
||||
/// </summary>
|
||||
public event EventHandler<MessageEventArgs<ChannelRequestMessage>> ChannelRequestReceived;
|
||||
internal event EventHandler<MessageEventArgs<ChannelRequestMessage>> ChannelRequestReceived;
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when <see cref="ChannelSuccessMessage"/> message received
|
||||
/// </summary>
|
||||
public event EventHandler<MessageEventArgs<ChannelSuccessMessage>> ChannelSuccessReceived;
|
||||
internal event EventHandler<MessageEventArgs<ChannelSuccessMessage>> ChannelSuccessReceived;
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when <see cref="ChannelFailureMessage"/> message received
|
||||
/// </summary>
|
||||
public event EventHandler<MessageEventArgs<ChannelFailureMessage>> ChannelFailureReceived;
|
||||
internal event EventHandler<MessageEventArgs<ChannelFailureMessage>> ChannelFailureReceived;
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when message received and is not handled by any of the event handlers
|
||||
/// </summary>
|
||||
public event EventHandler<MessageEventArgs<Message>> MessageReceived;
|
||||
internal event EventHandler<MessageEventArgs<Message>> MessageReceived;
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -553,12 +553,12 @@ namespace Renci.SshClient
|
||||
this.SendDisconnect(DisconnectReasons.ByApplication, "Connection terminated by the client.");
|
||||
}
|
||||
|
||||
public T CreateChannel<T>() where T : Channel, new()
|
||||
internal T CreateChannel<T>() where T : Channel, new()
|
||||
{
|
||||
return CreateChannel<T>(0, 0x100000, 0x8000);
|
||||
}
|
||||
|
||||
public T CreateChannel<T>(uint serverChannelNumber, uint windowSize, uint packetSize) where T : Channel, new()
|
||||
internal T CreateChannel<T>(uint serverChannelNumber, uint windowSize, uint packetSize) where T : Channel, new()
|
||||
{
|
||||
T channel = new T();
|
||||
lock (this)
|
||||
@@ -1008,7 +1008,7 @@ namespace Renci.SshClient
|
||||
{
|
||||
this._keyExchangeCompletedWaitHandle.Reset();
|
||||
|
||||
// Connection type messages are not allowed during key excahnge phase
|
||||
// Connection type messages are not allowed during key exchange phase
|
||||
this.UnRegisterMessageType(MessageTypes.GlobalRequest);
|
||||
this.UnRegisterMessageType(MessageTypes.RequestSuccess);
|
||||
this.UnRegisterMessageType(MessageTypes.RequestFailure);
|
||||
|
||||
@@ -8,39 +8,13 @@ namespace Renci.SshClient
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public class SftpClient : IDisposable
|
||||
public class SftpClient : SshBaseClient
|
||||
{
|
||||
/// <summary>
|
||||
/// Holds SftpSession instance that used to communicate to the SFTP server
|
||||
/// </summary>
|
||||
private SftpSession _sftpSession;
|
||||
|
||||
private Session _session;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the connection info.
|
||||
/// </summary>
|
||||
/// <value>The connection info.</value>
|
||||
public ConnectionInfo ConnectionInfo { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether client is connected.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// <c>true</c> if client is connected; otherwise, <c>false</c>.
|
||||
/// </value>
|
||||
public bool IsConnected
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this._session == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return this._session.IsConnected;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the operation timeout.
|
||||
/// </summary>
|
||||
@@ -60,10 +34,10 @@ namespace Renci.SshClient
|
||||
/// </summary>
|
||||
/// <param name="connectionInfo">The connection info.</param>
|
||||
public SftpClient(ConnectionInfo connectionInfo)
|
||||
: base(connectionInfo)
|
||||
{
|
||||
this.OperationTimeout = -1;
|
||||
this.BufferSize = 1024 * 16;
|
||||
this.ConnectionInfo = connectionInfo;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -74,7 +48,7 @@ namespace Renci.SshClient
|
||||
/// <param name="username">The username.</param>
|
||||
/// <param name="password">The password.</param>
|
||||
public SftpClient(string host, int port, string username, string password)
|
||||
: this(new ConnectionInfo
|
||||
: base(new ConnectionInfo
|
||||
{
|
||||
Host = host,
|
||||
Port = port,
|
||||
@@ -91,7 +65,7 @@ namespace Renci.SshClient
|
||||
/// <param name="username">The username.</param>
|
||||
/// <param name="password">The password.</param>
|
||||
public SftpClient(string host, string username, string password)
|
||||
: this(new ConnectionInfo
|
||||
: base(new ConnectionInfo
|
||||
{
|
||||
Host = host,
|
||||
Username = username,
|
||||
@@ -108,7 +82,7 @@ namespace Renci.SshClient
|
||||
/// <param name="username">The username.</param>
|
||||
/// <param name="keyFile">The key file.</param>
|
||||
public SftpClient(string host, int port, string username, PrivateKeyFile keyFile)
|
||||
: this(new ConnectionInfo
|
||||
: base(new ConnectionInfo
|
||||
{
|
||||
Host = host,
|
||||
Port = port,
|
||||
@@ -125,7 +99,7 @@ namespace Renci.SshClient
|
||||
/// <param name="username">The username.</param>
|
||||
/// <param name="keyFile">The key file.</param>
|
||||
public SftpClient(string host, string username, PrivateKeyFile keyFile)
|
||||
: this(new ConnectionInfo
|
||||
: base(new ConnectionInfo
|
||||
{
|
||||
Host = host,
|
||||
Username = username,
|
||||
@@ -136,38 +110,10 @@ namespace Renci.SshClient
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Connects client to the server.
|
||||
/// </summary>
|
||||
public void Connect()
|
||||
{
|
||||
if (this._session == null)
|
||||
{
|
||||
this._session = new Session(this.ConnectionInfo);
|
||||
}
|
||||
this._session.Connect();
|
||||
|
||||
this._sftpSession = new SftpSession(this._session, this.OperationTimeout);
|
||||
|
||||
this._sftpSession.Connect();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Disconnects client from the server.
|
||||
/// </summary>
|
||||
public void Disconnect()
|
||||
{
|
||||
this._sftpSession.Disconnect();
|
||||
|
||||
this._session.Disconnect();
|
||||
|
||||
this._session = null;
|
||||
}
|
||||
|
||||
#region List Directory
|
||||
|
||||
/// <summary>
|
||||
/// Begins the list directory.
|
||||
/// Begins the list directory operation.
|
||||
/// </summary>
|
||||
/// <param name="path">The path.</param>
|
||||
/// <param name="asyncCallback">The async callback.</param>
|
||||
@@ -183,10 +129,10 @@ namespace Renci.SshClient
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ends the list directory.
|
||||
/// Ends the list directory operation.
|
||||
/// </summary>
|
||||
/// <param name="asyncResult">An <see cref="IAsyncResult"/> that references the asynchronous operation.</param>
|
||||
/// <returns></returns>
|
||||
/// <returns>List of files</returns>
|
||||
public IEnumerable<SftpFile> EndListDirectory(IAsyncResult asyncResult)
|
||||
{
|
||||
var sftpAsyncResult = asyncResult as SftpAsyncResult;
|
||||
@@ -207,7 +153,7 @@ namespace Renci.SshClient
|
||||
/// Lists the directory.
|
||||
/// </summary>
|
||||
/// <param name="path">The path.</param>
|
||||
/// <returns></returns>
|
||||
/// <returns>List of files</returns>
|
||||
public IEnumerable<SftpFile> ListDirectory(string path)
|
||||
{
|
||||
return this.EndListDirectory(this.BeginListDirectory(path, null, null));
|
||||
@@ -554,51 +500,27 @@ namespace Renci.SshClient
|
||||
|
||||
#endregion
|
||||
|
||||
#region IDisposable Members
|
||||
|
||||
private bool disposed = false;
|
||||
|
||||
public void Dispose()
|
||||
/// <summary>
|
||||
/// Called when client is connected to the server.
|
||||
/// </summary>
|
||||
protected override void OnConnected()
|
||||
{
|
||||
Dispose(true);
|
||||
base.OnConnected();
|
||||
|
||||
GC.SuppressFinalize(this);
|
||||
this._sftpSession = new SftpSession(this.Session, this.OperationTimeout);
|
||||
|
||||
this._sftpSession.Connect();
|
||||
}
|
||||
|
||||
private void Dispose(bool disposing)
|
||||
/// <summary>
|
||||
/// Called when client is disconnecting from the server.
|
||||
/// </summary>
|
||||
protected override void OnDisconnecting()
|
||||
{
|
||||
// Check to see if Dispose has already been called.
|
||||
if (!this.disposed)
|
||||
{
|
||||
// If disposing equals true, dispose all managed
|
||||
// and unmanaged resources.
|
||||
if (disposing)
|
||||
{
|
||||
// Dispose managed resources.
|
||||
if (this._session != null)
|
||||
{
|
||||
this._session.Dispose();
|
||||
}
|
||||
if (this._sftpSession != null)
|
||||
{
|
||||
this._sftpSession.Dispose();
|
||||
}
|
||||
}
|
||||
base.OnDisconnecting();
|
||||
|
||||
// Note disposing has been done.
|
||||
disposed = true;
|
||||
}
|
||||
this._sftpSession.Disconnect();
|
||||
}
|
||||
|
||||
~SftpClient()
|
||||
{
|
||||
// Do not re-create Dispose clean-up code here.
|
||||
// Calling Dispose(false) is optimal in terms of
|
||||
// readability and maintainability.
|
||||
Dispose(false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,161 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
using Renci.SshClient.Sftp;
|
||||
|
||||
namespace Renci.SshClient
|
||||
{
|
||||
public abstract class SshBaseClient : IDisposable
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets current session.
|
||||
/// </summary>
|
||||
protected Session Session { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the connection info.
|
||||
/// </summary>
|
||||
public ConnectionInfo ConnectionInfo { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether this client is connected to the server.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// <c>true</c> if this client is connected; otherwise, <c>false</c>.
|
||||
/// </value>
|
||||
public bool IsConnected
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this.Session == null)
|
||||
return false;
|
||||
else
|
||||
return this.Session.IsConnected;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="SshBaseClient"/> class.
|
||||
/// </summary>
|
||||
/// <param name="connectionInfo">The connection info.</param>
|
||||
public SshBaseClient(ConnectionInfo connectionInfo)
|
||||
{
|
||||
this.ConnectionInfo = connectionInfo;
|
||||
this.Session = new Session(connectionInfo);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Connects client to the server.
|
||||
/// </summary>
|
||||
public void Connect()
|
||||
{
|
||||
this.OnConnecting();
|
||||
|
||||
if (this.IsConnected)
|
||||
{
|
||||
this.Session.Disconnect();
|
||||
}
|
||||
|
||||
this.Session = new Session(this.ConnectionInfo);
|
||||
this.Session.Connect();
|
||||
|
||||
this.OnConnected();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Disconnects client from the server.
|
||||
/// </summary>
|
||||
public void Disconnect()
|
||||
{
|
||||
this.OnDisconnecting();
|
||||
|
||||
this.Session.Disconnect();
|
||||
|
||||
this.OnDisconnected();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sends keep-alive message to the server.
|
||||
/// </summary>
|
||||
public void KeepAlive()
|
||||
{
|
||||
this.Session.KeepAlive();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called when client is connecting to the server.
|
||||
/// </summary>
|
||||
protected virtual void OnConnecting()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called when client is connected to the server.
|
||||
/// </summary>
|
||||
protected virtual void OnConnected()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called when client is disconnecting from the server.
|
||||
/// </summary>
|
||||
protected virtual void OnDisconnecting()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called when client is disconnected from the server.
|
||||
/// </summary>
|
||||
protected virtual void OnDisconnected()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
#region IDisposable Members
|
||||
|
||||
private bool disposed = false;
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
private void Dispose(bool disposing)
|
||||
{
|
||||
// Check to see if Dispose has already been called.
|
||||
if (!this.disposed)
|
||||
{
|
||||
// If disposing equals true, dispose all managed
|
||||
// and unmanaged resources.
|
||||
if (disposing)
|
||||
{
|
||||
// Dispose managed resources.
|
||||
if (this.Session != null)
|
||||
{
|
||||
this.Session.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
// Note disposing has been done.
|
||||
disposed = true;
|
||||
}
|
||||
}
|
||||
|
||||
~SshBaseClient()
|
||||
{
|
||||
// Do not re-create Dispose clean-up code here.
|
||||
// Calling Dispose(false) is optimal in terms of
|
||||
// readability and maintainability.
|
||||
Dispose(false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -4,25 +4,16 @@ using System.IO;
|
||||
|
||||
namespace Renci.SshClient
|
||||
{
|
||||
public class SshClient : IDisposable
|
||||
public class SshClient : SshBaseClient
|
||||
{
|
||||
private Session _session;
|
||||
|
||||
/// <summary>
|
||||
/// Holds the list of forwarded ports
|
||||
/// </summary>
|
||||
private List<ForwardedPort> _forwardedPorts = new List<ForwardedPort>();
|
||||
|
||||
public ConnectionInfo ConnectionInfo { get; private set; }
|
||||
|
||||
public bool IsConnected
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this._session == null)
|
||||
return false;
|
||||
else
|
||||
return this._session.IsConnected;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the list of forwarded ports.
|
||||
/// </summary>
|
||||
public IEnumerable<ForwardedPort> ForwardedPorts
|
||||
{
|
||||
get
|
||||
@@ -31,14 +22,15 @@ namespace Renci.SshClient
|
||||
}
|
||||
}
|
||||
|
||||
#region Constructors
|
||||
|
||||
public SshClient(ConnectionInfo connectionInfo)
|
||||
: base(connectionInfo)
|
||||
{
|
||||
this.ConnectionInfo = connectionInfo;
|
||||
this._session = new Session(connectionInfo);
|
||||
}
|
||||
|
||||
public SshClient(string host, int port, string username, string password)
|
||||
: this(new ConnectionInfo
|
||||
: base(new ConnectionInfo
|
||||
{
|
||||
Host = host,
|
||||
Port = port,
|
||||
@@ -49,7 +41,7 @@ namespace Renci.SshClient
|
||||
}
|
||||
|
||||
public SshClient(string host, string username, string password)
|
||||
: this(new ConnectionInfo
|
||||
: base(new ConnectionInfo
|
||||
{
|
||||
Host = host,
|
||||
Username = username,
|
||||
@@ -59,7 +51,7 @@ namespace Renci.SshClient
|
||||
}
|
||||
|
||||
public SshClient(string host, int port, string username, PrivateKeyFile keyFile)
|
||||
: this(new ConnectionInfo
|
||||
: base(new ConnectionInfo
|
||||
{
|
||||
Host = host,
|
||||
Port = port,
|
||||
@@ -70,7 +62,7 @@ namespace Renci.SshClient
|
||||
}
|
||||
|
||||
public SshClient(string host, string username, PrivateKeyFile keyFile)
|
||||
: this(new ConnectionInfo
|
||||
: base(new ConnectionInfo
|
||||
{
|
||||
Host = host,
|
||||
Username = username,
|
||||
@@ -79,29 +71,34 @@ namespace Renci.SshClient
|
||||
{
|
||||
}
|
||||
|
||||
public void Connect()
|
||||
{
|
||||
this._session = new Session(this.ConnectionInfo);
|
||||
this._session.Connect();
|
||||
}
|
||||
#endregion
|
||||
|
||||
public void Disconnect()
|
||||
/// <summary>
|
||||
/// Called when client is disconnecting from the server.
|
||||
/// </summary>
|
||||
protected override void OnDisconnecting()
|
||||
{
|
||||
base.OnDisconnecting();
|
||||
|
||||
foreach (var port in this._forwardedPorts)
|
||||
{
|
||||
port.Stop();
|
||||
}
|
||||
this._session.Disconnect();
|
||||
|
||||
// Clean up objects created using previouse session instance
|
||||
//this._sftp = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds forwarded port to the list.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Type of forwarded port to add</typeparam>
|
||||
/// <param name="boundPort">The bound port.</param>
|
||||
/// <param name="connectedHost">The connected host.</param>
|
||||
/// <param name="connectedPort">The connected port.</param>
|
||||
/// <returns>Forwarded port</returns>
|
||||
public T AddForwardedPort<T>(uint boundPort, string connectedHost, uint connectedPort) where T : ForwardedPort, new()
|
||||
{
|
||||
T port = new T();
|
||||
|
||||
port.Session = this._session;
|
||||
port.Session = this.Session;
|
||||
port.BoundPort = boundPort;
|
||||
port.ConnectedHost = connectedHost;
|
||||
port.ConnectedPort = connectedPort;
|
||||
@@ -111,6 +108,10 @@ namespace Renci.SshClient
|
||||
return port;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stops and removes the forwarded port from the list.
|
||||
/// </summary>
|
||||
/// <param name="port">Forwarded port.</param>
|
||||
public void RemoveForwardedPort(ForwardedPort port)
|
||||
{
|
||||
// Stop port forwarding before removing it
|
||||
@@ -119,16 +120,21 @@ namespace Renci.SshClient
|
||||
this._forwardedPorts.Remove(port);
|
||||
}
|
||||
|
||||
public void KeepAlive()
|
||||
{
|
||||
this._session.KeepAlive();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates the command to be executed.
|
||||
/// </summary>
|
||||
/// <param name="commandText">The command text.</param>
|
||||
/// <returns></returns>
|
||||
public SshCommand CreateCommand(string commandText)
|
||||
{
|
||||
return new SshCommand(this._session, commandText);
|
||||
return new SshCommand(this.Session, commandText);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates and executes the command.
|
||||
/// </summary>
|
||||
/// <param name="commandText">The command text.</param>
|
||||
/// <returns></returns>
|
||||
public SshCommand RunCommand(string commandText)
|
||||
{
|
||||
var cmd = this.CreateCommand(commandText);
|
||||
@@ -136,51 +142,22 @@ namespace Renci.SshClient
|
||||
return cmd;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates the shell. (not complete)
|
||||
/// </summary>
|
||||
/// <param name="input">The input.</param>
|
||||
/// <param name="output">The output.</param>
|
||||
/// <param name="extendedOutput">The extended output.</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>
|
||||
/// <returns></returns>
|
||||
public Shell CreateShell(Stream input, TextWriter output, TextWriter extendedOutput, string terminalName, uint columns, uint rows, uint width, uint height, string terminalMode)
|
||||
{
|
||||
return new Shell(this._session, input, output, extendedOutput, terminalName, columns, rows, width, height, terminalMode);
|
||||
return new Shell(this.Session, input, output, extendedOutput, terminalName, columns, rows, width, height, terminalMode);
|
||||
}
|
||||
|
||||
#region IDisposable Members
|
||||
|
||||
private bool disposed = false;
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
private void Dispose(bool disposing)
|
||||
{
|
||||
// Check to see if Dispose has already been called.
|
||||
if (!this.disposed)
|
||||
{
|
||||
// If disposing equals true, dispose all managed
|
||||
// and unmanaged resources.
|
||||
if (disposing)
|
||||
{
|
||||
// Dispose managed resources.
|
||||
if (this._session != null)
|
||||
{
|
||||
this._session.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
// Note disposing has been done.
|
||||
disposed = true;
|
||||
}
|
||||
}
|
||||
|
||||
~SshClient()
|
||||
{
|
||||
// Do not re-create Dispose clean-up code here.
|
||||
// Calling Dispose(false) is optimal in terms of
|
||||
// readability and maintainability.
|
||||
Dispose(false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user