当我使用SSH.NET库连接到服务器时,默认文件夹为/mif/stud3/2014/rira1874。当我执行
res = ssh.CreateCommand("cd existingFolder").Execute();
Console.WriteLine(res);
Run Code Online (Sandbox Code Playgroud)
它仍然保留在默认连接文件夹中。怎么了
完整代码:
public void ConnectWithPassword(string username, string password, string domain, int port)
{
bool i = true;
using (var ssh = new SshClient(CreatePasswordConnectionInfo(username, password, domain)))
{
try
{
ssh.Connect();
if (ssh.IsConnected)
{
while(i == true)
{
string res = Regex.Replace(ssh.CreateCommand("pwd").Execute(), @"\r\n?|\n", "");
Console.Write(res + ": ");
res = ssh.CreateCommand(Console.ReadLine()).Execute();
Console.WriteLine(res);
}
}
else {
Console.WriteLine("Not connected");
}
ssh.Disconnect();
}
catch (Exception e)
{
Console.WriteLine("Exception caught: {0}", e);
}
}
}
Run Code Online (Sandbox Code Playgroud)
尝试执行以下操作
string cmdstr = "cd /etc; ls -la";
ssh.Connect();
var cmd = ssh.RunCommand(cmdstr);
var result = cmd.Result;
基本上ssh.net不允许/支持(我猜)。替代方法是您可以转到目录并执行所需的相应命令。如果您需要执行一些文件,只需使用上面的示例“ cd / etc; ./yourFile”。确保包含分号“;” 因此您可以继续执行。
| 归档时间: |
|
| 查看次数: |
3087 次 |
| 最近记录: |