Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -753,6 +753,18 @@ public override SwitchParameter SSHTransport
set { base.SSHTransport = value; }
}

/// <summary>
/// This parameter allows you to specify a custom executable name to use for the SSH transport. The executable must be on the path.
/// </summary>
[Parameter(ParameterSetName = PSRemotingBaseCmdlet.SSHHostParameterSet)]
[Parameter(ParameterSetName = InvokeCommandCommand.FilePathSSHHostParameterSet)]
public override string SSHTransportPath
{
get { return base.SSHTransportPath; }

set { base.SSHTransportPath = value; }
}

/// <summary>
/// Hashtable array containing SSH connection parameters for each remote target
/// ComputerName (Alias: HostName) (required)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,16 @@ public virtual SwitchParameter SSHTransport
set;
}

/// <summary>
/// Gets or sets a custom executable name to use for the SSH transport. The executable must be on the path.
/// </summary>
[Parameter(ParameterSetName = PSRemotingBaseCmdlet.SSHHostParameterSet)]
public virtual string SSHTransportPath
{
get;
set;
}

/// <summary>
/// Hashtable array containing SSH connection parameters for each remote target
/// ComputerName (Alias: HostName) (required)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1262,7 +1262,7 @@ private RemoteRunspace GetRunspaceForContainerSession()
private RemoteRunspace GetRunspaceForSSHSession()
{
ParseSshHostName(HostName, out string host, out string userName, out int port);
var sshConnectionInfo = new SSHConnectionInfo(userName, host, this.KeyFilePath, port, this.Subsystem);
var sshConnectionInfo = new SSHConnectionInfo(userName, host, KeyFilePath, port, Subsystem, SSHTransportPath);
var typeTable = TypeTable.LoadDefaultTypeFiles();

// Use the class _tempRunspace field while the runspace is being opened so that StopProcessing can be handled at that time.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1892,6 +1892,15 @@ private string Subsystem
set;
}

/// <summary>
/// Gets or sets the name of the ssh executable to use.
/// </summary>
private string SshPath
{
get;
set;
}

#endregion

#region Constructors
Expand Down Expand Up @@ -1960,6 +1969,26 @@ public SSHConnectionInfo(
this.Port = port;
this.Subsystem = (string.IsNullOrEmpty(subsystem)) ? DefaultSubsystem : subsystem;
}

/// <summary>
/// Initializes a new instance of the SSHConnectionInfo class.
/// </summary>
/// <param name="userName">User Name.</param>
/// <param name="computerName">Computer Name.</param>
/// <param name="keyFilePath">Key File Path.</param>
/// <param name="port">Port number for connection (default 22).</param>
/// <param name="subsystem">Subsystem to use (default 'powershell').</param>
/// <param name="sshPath">Name or path to ssh executable (default 'ssh' or 'ssh.exe')'.</param>
public SSHConnectionInfo(
string userName,
string computerName,
string keyFilePath,
int port,
string subsystem,
string sshPath) : this(userName, computerName, keyFilePath, port, subsystem)
{
this.SshPath = sshPath;
}

#endregion

Expand Down Expand Up @@ -2016,6 +2045,7 @@ internal override RunspaceConnectionInfo InternalCopy()
newCopy.KeyFilePath = this.KeyFilePath;
newCopy.Port = this.Port;
newCopy.Subsystem = this.Subsystem;
newCopy.SshPath = this.SshPath;

return newCopy;
}
Expand Down Expand Up @@ -2049,15 +2079,19 @@ internal int StartSSHProcess(
out StreamReader stdErrReaderVar)
{
string filePath = string.Empty;
#if UNIX
const string sshCommand = "ssh";
#else
const string sshCommand = "ssh.exe";
#endif
if (SshPath == null)
{
#if UNIX
SshPath = "ssh";
#else
SshPath = "ssh.exe";
#endif
}

var context = Runspaces.LocalPipeline.GetExecutionContextFromTLS();
if (context != null)
{
var cmdInfo = context.CommandDiscovery.LookupCommandInfo(sshCommand, CommandOrigin.Internal) as ApplicationInfo;
var cmdInfo = context.CommandDiscovery.LookupCommandInfo(SshPath, CommandOrigin.Internal) as ApplicationInfo;
if (cmdInfo != null)
{
filePath = cmdInfo.Path;
Expand Down