Build initial MCP SSH server
This commit is contained in:
36
src/McpSsh.Server/Ssh/RemoteShellCommand.cs
Normal file
36
src/McpSsh.Server/Ssh/RemoteShellCommand.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using System.Text;
|
||||
|
||||
namespace McpSsh.Server.Ssh;
|
||||
|
||||
public static class RemoteShellCommand
|
||||
{
|
||||
public static string Build(string command, string? cwd)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(cwd))
|
||||
{
|
||||
return command;
|
||||
}
|
||||
|
||||
return $"cd {Quote(cwd)} && {command}";
|
||||
}
|
||||
|
||||
public static string Quote(string value)
|
||||
{
|
||||
var builder = new StringBuilder(value.Length + 2);
|
||||
builder.Append('\'');
|
||||
foreach (var character in value)
|
||||
{
|
||||
if (character == '\'')
|
||||
{
|
||||
builder.Append("'\\''");
|
||||
}
|
||||
else
|
||||
{
|
||||
builder.Append(character);
|
||||
}
|
||||
}
|
||||
|
||||
builder.Append('\'');
|
||||
return builder.ToString();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user