mirror of
https://github.com/sshnet/SSH.NET.git
synced 2026-10-28 22:49:59 +08:00
Remove EnsureConnection and move its funcionality into Session.SendMessage method
This commit is contained in:
@@ -180,17 +180,7 @@ namespace Renci.SshNet
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ensures that client is connected.
|
||||
/// </summary>
|
||||
/// <exception cref="Renci.SshNet.Common.SshConnectionException">When client not connected.</exception>
|
||||
protected void EnsureConnection()
|
||||
{
|
||||
if (!this.Session.IsConnected)
|
||||
throw new SshConnectionException("Client not connected.");
|
||||
}
|
||||
|
||||
private void Session_ErrorOccured(object sender, ExceptionEventArgs e)
|
||||
private void Session_ErrorOccured(object sender, ExceptionEventArgs e)
|
||||
{
|
||||
if (this.ErrorOccurred != null)
|
||||
{
|
||||
|
||||
@@ -116,7 +116,6 @@ namespace Renci.SshNet
|
||||
{
|
||||
get
|
||||
{
|
||||
this.EnsureConnection();
|
||||
return this._netConfSession.ServerCapabilities;
|
||||
}
|
||||
}
|
||||
@@ -129,7 +128,6 @@ namespace Renci.SshNet
|
||||
{
|
||||
get
|
||||
{
|
||||
this.EnsureConnection();
|
||||
return this._netConfSession.ClientCapabilities;
|
||||
}
|
||||
}
|
||||
@@ -150,7 +148,6 @@ namespace Renci.SshNet
|
||||
/// <exception cref="SshConnectionException">Client is not connected.</exception>
|
||||
public XmlDocument SendReceiveRpc(XmlDocument rpc)
|
||||
{
|
||||
this.EnsureConnection();
|
||||
return this._netConfSession.SendReceiveRpc(rpc, this.AutomaticMessageIdHandling);
|
||||
}
|
||||
|
||||
@@ -173,8 +170,6 @@ namespace Renci.SshNet
|
||||
/// <exception cref="SshConnectionException">Client is not connected.</exception>
|
||||
public XmlDocument SendCloseRpc()
|
||||
{
|
||||
this.EnsureConnection();
|
||||
|
||||
XmlDocument rpc = new XmlDocument();
|
||||
|
||||
rpc.LoadXml("<?xml version=\"1.0\" encoding=\"UTF-8\"?><rpc message-id=\"6666\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\"><close-session/></rpc>");
|
||||
|
||||
@@ -31,9 +31,6 @@ namespace Renci.SshNet
|
||||
if (string.IsNullOrEmpty(filename))
|
||||
throw new ArgumentException("filename");
|
||||
|
||||
// Ensure that connection is established.
|
||||
this.EnsureConnection();
|
||||
|
||||
using (var input = new PipeStream())
|
||||
using (var channel = this.Session.CreateChannel<ChannelSession>())
|
||||
{
|
||||
@@ -70,9 +67,6 @@ namespace Renci.SshNet
|
||||
if (string.IsNullOrEmpty(filename))
|
||||
throw new ArgumentException("filename");
|
||||
|
||||
// Ensure that connection is established.
|
||||
this.EnsureConnection();
|
||||
|
||||
using (var input = new PipeStream())
|
||||
using (var channel = this.Session.CreateChannel<ChannelSession>())
|
||||
{
|
||||
@@ -108,9 +102,6 @@ namespace Renci.SshNet
|
||||
if (string.IsNullOrEmpty(filename))
|
||||
throw new ArgumentException("filename");
|
||||
|
||||
// Ensure that connection is established.
|
||||
this.EnsureConnection();
|
||||
|
||||
using (var input = new PipeStream())
|
||||
using (var channel = this.Session.CreateChannel<ChannelSession>())
|
||||
{
|
||||
@@ -146,9 +137,6 @@ namespace Renci.SshNet
|
||||
if (string.IsNullOrEmpty(directoryName))
|
||||
throw new ArgumentException("directoryName");
|
||||
|
||||
// Ensure that connection is established.
|
||||
this.EnsureConnection();
|
||||
|
||||
using (var input = new PipeStream())
|
||||
using (var channel = this.Session.CreateChannel<ChannelSession>())
|
||||
{
|
||||
|
||||
@@ -144,9 +144,6 @@ namespace Renci.SshNet
|
||||
/// <param name="filename">Remote host file name.</param>
|
||||
public void Upload(Stream source, string filename)
|
||||
{
|
||||
// Ensure that connection is established.
|
||||
this.EnsureConnection();
|
||||
|
||||
using (var input = new PipeStream())
|
||||
using (var channel = this.Session.CreateChannel<ChannelSession>())
|
||||
{
|
||||
@@ -184,9 +181,6 @@ namespace Renci.SshNet
|
||||
if (destination == null)
|
||||
throw new ArgumentNullException("destination");
|
||||
|
||||
// Ensure that connection is established.
|
||||
this.EnsureConnection();
|
||||
|
||||
using (var input = new PipeStream())
|
||||
using (var channel = this.Session.CreateChannel<ChannelSession>())
|
||||
{
|
||||
|
||||
@@ -652,8 +652,8 @@ namespace Renci.SshNet
|
||||
/// <param name="message">The message.</param>
|
||||
internal void SendMessage(Message message)
|
||||
{
|
||||
if (this._socket == null || !this._socket.Connected)
|
||||
return;
|
||||
if (!this.IsConnected)
|
||||
throw new SshConnectionException("Client not connected.");
|
||||
|
||||
if (this._keyExchangeInProgress && !(message is IKeyExchangedAllowed))
|
||||
{
|
||||
|
||||
@@ -51,9 +51,6 @@ namespace Renci.SshNet
|
||||
if (destinationPath.IsNullOrWhiteSpace())
|
||||
throw new ArgumentException("destDir");
|
||||
|
||||
// Ensure that connection is established.
|
||||
this.EnsureConnection();
|
||||
|
||||
var asyncResult = new SftpSynchronizeDirectoriesAsyncResult(asyncCallback, state);
|
||||
|
||||
this.ExecuteThread(() =>
|
||||
|
||||
@@ -142,10 +142,7 @@ namespace Renci.SshNet
|
||||
{
|
||||
if (path == null)
|
||||
throw new ArgumentNullException("path");
|
||||
|
||||
// Ensure that connection is established.
|
||||
this.EnsureConnection();
|
||||
|
||||
|
||||
this._sftpSession.ChangeDirectory(path);
|
||||
}
|
||||
|
||||
@@ -179,9 +176,6 @@ namespace Renci.SshNet
|
||||
if (path.IsNullOrWhiteSpace())
|
||||
throw new ArgumentException(path);
|
||||
|
||||
// Ensure that connection is established.
|
||||
this.EnsureConnection();
|
||||
|
||||
var fullPath = this._sftpSession.GetCanonicalPath(path);
|
||||
|
||||
this._sftpSession.RequestMkDir(fullPath);
|
||||
@@ -200,9 +194,6 @@ namespace Renci.SshNet
|
||||
if (path.IsNullOrWhiteSpace())
|
||||
throw new ArgumentException("path");
|
||||
|
||||
// Ensure that connection is established.
|
||||
this.EnsureConnection();
|
||||
|
||||
var fullPath = this._sftpSession.GetCanonicalPath(path);
|
||||
|
||||
this._sftpSession.RequestRmDir(fullPath);
|
||||
@@ -221,9 +212,6 @@ namespace Renci.SshNet
|
||||
if (path.IsNullOrWhiteSpace())
|
||||
throw new ArgumentException("path");
|
||||
|
||||
// Ensure that connection is established.
|
||||
this.EnsureConnection();
|
||||
|
||||
var fullPath = this._sftpSession.GetCanonicalPath(path);
|
||||
|
||||
this._sftpSession.RequestRemove(fullPath);
|
||||
@@ -262,9 +250,6 @@ namespace Renci.SshNet
|
||||
if (newPath == null)
|
||||
throw new ArgumentNullException("newPath");
|
||||
|
||||
// Ensure that connection is established.
|
||||
this.EnsureConnection();
|
||||
|
||||
var oldFullPath = this._sftpSession.GetCanonicalPath(oldPath);
|
||||
|
||||
var newFullPath = this._sftpSession.GetCanonicalPath(newPath);
|
||||
@@ -296,9 +281,6 @@ namespace Renci.SshNet
|
||||
if (linkPath.IsNullOrWhiteSpace())
|
||||
throw new ArgumentException("linkPath");
|
||||
|
||||
// Ensure that connection is established.
|
||||
this.EnsureConnection();
|
||||
|
||||
var fullPath = this._sftpSession.GetCanonicalPath(path);
|
||||
|
||||
var linkFullPath = this._sftpSession.GetCanonicalPath(linkPath);
|
||||
@@ -394,9 +376,6 @@ namespace Renci.SshNet
|
||||
if (path == null)
|
||||
throw new ArgumentNullException("path");
|
||||
|
||||
// Ensure that connection is established.
|
||||
this.EnsureConnection();
|
||||
|
||||
var fullPath = this._sftpSession.GetCanonicalPath(path);
|
||||
|
||||
var attributes = this._sftpSession.RequestLStat(fullPath);
|
||||
@@ -418,9 +397,6 @@ namespace Renci.SshNet
|
||||
if (path.IsNullOrWhiteSpace())
|
||||
throw new ArgumentException("path");
|
||||
|
||||
// Ensure that connection is established.
|
||||
this.EnsureConnection();
|
||||
|
||||
var fullPath = this._sftpSession.GetCanonicalPath(path);
|
||||
|
||||
// Try to open as a file
|
||||
@@ -490,9 +466,6 @@ namespace Renci.SshNet
|
||||
if (output == null)
|
||||
throw new ArgumentNullException("output");
|
||||
|
||||
// Ensure that connection is established.
|
||||
this.EnsureConnection();
|
||||
|
||||
var asyncResult = new SftpDownloadAsyncResult(asyncCallback, state);
|
||||
|
||||
this.ExecuteThread(() =>
|
||||
@@ -643,9 +616,6 @@ namespace Renci.SshNet
|
||||
else
|
||||
flags |= Flags.CreateNew;
|
||||
|
||||
// Ensure that connection is established.
|
||||
this.EnsureConnection();
|
||||
|
||||
var asyncResult = new SftpUploadAsyncResult(asyncCallback, state);
|
||||
|
||||
this.ExecuteThread(() =>
|
||||
@@ -704,9 +674,6 @@ namespace Renci.SshNet
|
||||
if (path == null)
|
||||
throw new ArgumentNullException("path");
|
||||
|
||||
// Ensure that connection is established.
|
||||
this.EnsureConnection();
|
||||
|
||||
var fullPath = this._sftpSession.GetCanonicalPath(path);
|
||||
|
||||
return this._sftpSession.RequestStatVfs(fullPath);
|
||||
@@ -1280,9 +1247,6 @@ namespace Renci.SshNet
|
||||
if (path == null)
|
||||
throw new ArgumentNullException("path");
|
||||
|
||||
// Ensure that connection is established.
|
||||
this.EnsureConnection();
|
||||
|
||||
var fullPath = this._sftpSession.GetCanonicalPath(path);
|
||||
|
||||
var handle = this._sftpSession.RequestOpenDir(fullPath);
|
||||
@@ -1335,9 +1299,6 @@ namespace Renci.SshNet
|
||||
if (path.IsNullOrWhiteSpace())
|
||||
throw new ArgumentException("path");
|
||||
|
||||
// Ensure that connection is established.
|
||||
this.EnsureConnection();
|
||||
|
||||
var fullPath = this._sftpSession.GetCanonicalPath(path);
|
||||
|
||||
var handle = this._sftpSession.RequestOpen(fullPath, Flags.Read);
|
||||
@@ -1388,9 +1349,6 @@ namespace Renci.SshNet
|
||||
if (path.IsNullOrWhiteSpace())
|
||||
throw new ArgumentException("path");
|
||||
|
||||
// Ensure that connection is established.
|
||||
this.EnsureConnection();
|
||||
|
||||
var fullPath = this._sftpSession.GetCanonicalPath(path);
|
||||
|
||||
var handle = this._sftpSession.RequestOpen(fullPath, flags);
|
||||
|
||||
@@ -156,9 +156,6 @@ namespace Renci.SshNet
|
||||
if (port == null)
|
||||
throw new ArgumentNullException("port");
|
||||
|
||||
// Ensure that connection is established.
|
||||
this.EnsureConnection();
|
||||
|
||||
if (port.Session != null && port.Session != this.Session)
|
||||
throw new InvalidOperationException("Forwarded port is already added to a different client.");
|
||||
|
||||
@@ -206,9 +203,6 @@ namespace Renci.SshNet
|
||||
/// <exception cref="ArgumentNullException"><paramref name="commandText"/> or <paramref name="encoding"/> is null.</exception>
|
||||
public SshCommand CreateCommand(string commandText, Encoding encoding)
|
||||
{
|
||||
// Ensure that connection is established.
|
||||
this.EnsureConnection();
|
||||
|
||||
return new SshCommand(this.Session, commandText, encoding);
|
||||
}
|
||||
|
||||
@@ -252,9 +246,6 @@ namespace Renci.SshNet
|
||||
/// </returns>
|
||||
public Shell CreateShell(Stream input, Stream output, Stream extendedOutput, string terminalName, uint columns, uint rows, uint width, uint height, IDictionary<TerminalModes, uint> terminalModes, int bufferSize)
|
||||
{
|
||||
// Ensure that connection is established.
|
||||
this.EnsureConnection();
|
||||
|
||||
return new Shell(this.Session, input, output, extendedOutput, terminalName, columns, rows, width, height, terminalModes, bufferSize);
|
||||
}
|
||||
|
||||
@@ -388,9 +379,6 @@ namespace Renci.SshNet
|
||||
/// </returns>
|
||||
public ShellStream CreateShellStream(string terminalName, uint columns, uint rows, uint width, uint height, int bufferSize, IDictionary<TerminalModes, uint> terminalModeValues)
|
||||
{
|
||||
// Ensure that connection is established.
|
||||
this.EnsureConnection();
|
||||
|
||||
return new ShellStream(this.Session, terminalName, columns, rows, width, height, bufferSize, terminalModeValues);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user