【发布时间】:2016-04-13 16:00:21
【问题描述】:
当我使用 SSH.NET 库连接到服务器时,默认文件夹是 /mif/stud3/2014/rira1874。当我执行
res = ssh.CreateCommand("cd existingFolder").Execute();
Console.WriteLine(res);
它仍然保留在默认连接文件夹中。这里有什么问题?
完整代码:
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);
}
}
}
【问题讨论】:
-
我没有看到问题与您的代码中的问题相同 ---> 您的代码有
res = ssh.CreateCommand(Console.ReadLine()).Execute();,而您正在谈论的是res = ssh.CreateCommand("cd existingFolder").Execute();! -
我的意思是,当我在控制台中写“cd existingFolder”时,它仍然没有改变目录