Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

C # establishes SSH connection with Linux server through SharpSSH library and executes commands

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

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

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report