C # establishes SSH connection with Linux server through SharpSSH library and executes commands
When developing tools for Unity3D projects, you need to use SSH to connect to the remote Linux server to execute commands. After you find the SharpSSH link library, you can use this method.
/ SSH logs in to the remote Linux server and runs the command / remote Linux server IP or domain name / account name / / account password / / command / public static bool RunSSHCommands (String host, String username, String password, String [] commands) {if (commands = = null | | commands.Length = = 0) return false Try {SshExec exec = new SshExec (host, username); exec.Password = password; / / XXLog.Log (String.Format ("[{0}] Connecting...", host)); exec.Connect (); / / XXLog.Log ("OK") Foreach (String command in commands) {if (command = = null | | command.Trim (). Length = = 0) continue; string output = exec.RunCommand (command); / / XXLog.Log (output);} / / XXLog.Log ("Disconnecting..."); exec.Close () / / XXLog.Log ("OK"); return true;} catch (Exception e) {XXLog.Log (e.Message); return false;}}
Attachment: http://down.51cto.com/data/2366664