I'd like to run a command over ssh from a windows box running using c#

前端 未结 6 1809
天命终不由人
天命终不由人 2021-01-02 08:31

Note that this has to be on a windows box as I am using c# to access information about windows

(I need information from both a windows box and a linux box, plus I th

6条回答
  •  太阳男子
    2021-01-02 08:53

    I used SharpSsh lib to make an asynchronous directory sync program between linux and windows boxes (i choosed sftp for secure file tranfer). Remained unchanged for years doesn't mean it is unsecure.

    it is really easy to use:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Tamir.SharpSsh;
    
    namespace sftpex
    {
        class Program
        {
            static void Main(string[] args)
            {
                try
                {
                    SshExec exec = new SshExec(ipAddress, username, password);
                    Console.Write("Connecting...");
                    exec.Connect();
                    Console.WriteLine("OK");
                    if (exec.Connected)
                        Console.WriteLine(exec.Cipher);
    
                    while (true)
                    {
                        Console.Write("Enter a command to execute ['Enter' to cancel]: ");
                        string command = Console.ReadLine();
                        if (command == "") break;
                        string output = exec.RunCommand(command);
                        string[] m = output.Split('\n');
                        for(int i=0; i

提交回复
热议问题