简体   繁体   中英

Run OpenWRT commands in C# using ssh client libraries

I want to run commands related to Openwrt in my C# application.I use renci ssh.net and also SharpSSH libraries to run the commands.They work fine in running other commands eg free,cat,df etc... but return with not found for others like uci and wifi.Here is my code runs without any error:

SshClient Client = new SshClient("192.168.1.1", "root", "12334456");
Client.Connect();
SshCommand sc= Client.CreateCommand("uci set wireless.@wifi-iface[1].disabled=1");
sc.Execute();

After running sc.error has below value:

"ash: uci: not found"

also running other commands like wifi have similar result.I don't have such a problem using putty. How can I run these commands in my c# application?

After some days of try and error finally kind Chilkat Software support answer my question :

I think the solution is to not use SendReqExec and instead do a shell session (like PuTTY). The SendReqExec method is the equivalent of running a remote command via the "rexec" Linux/Unix command. It's not quite the same as a full-blown shell session.

Most of SSH library have something like stream or shell.I try that and the error didn't appear anymore.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM