无法使用C#SSH.NET更改目录

weixin_38051760 2019-09-12 12:02:37
当我使用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); } } }
...全文
176 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
weixin_38058190 2019-09-12
  • 打赏
  • 举报
回复
尝试执行以下操作string cmdstr =“cd / etc; ls -la”;ssh.Connect();var cmd = ssh.RunCommand(cmdstr);var result = cmd.Result; 基本上ssh.net不允许/支持(我猜).替代方案是您可以更改到目录并执行所需的相应命令.如果你需要执行一些文件,只需使用上面的例子“cd / etc; ./yourFile”.确保包含分号“;”所以你可以继续执行.

433

社区成员

发帖
与我相关
我的任务
社区描述
其他技术讨论专区
其他 技术论坛(原bbs)
社区管理员
  • 其他技术讨论专区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧