Run OpenWRT commands in C# using ssh client libraries

782 views Asked by At

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 e.g. 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?

1

There are 1 answers

0
harsini On

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.