当前位置: 首页>>代码示例>>C#>>正文


C# SshClient.RunCommand方法代码示例

本文整理汇总了C#中Renci.SshNet.SshClient.RunCommand方法的典型用法代码示例。如果您正苦于以下问题:C# SshClient.RunCommand方法的具体用法?C# SshClient.RunCommand怎么用?C# SshClient.RunCommand使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Renci.SshNet.SshClient的用法示例。


在下文中一共展示了SshClient.RunCommand方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Execute

        /// <summary>
        /// Copy from source to target
        /// </summary>
        /// <returns></returns>
        public override bool Execute(SshClient client)
        {
            bool success = false;
            try
            {
                Debug.WriteLine("ExtractCommand");

                var command1 = client.RunCommand("tar xzvf " + Target);
                var s1 = command1.Result;
                Output = s1;

                var command2 = client.RunCommand("echo $?");
                var s2 = command2.Result;
                
                var arrRsp = s2.Split(new[] {"\n"}, StringSplitOptions.None);

                if(arrRsp.Length > 0)
                    if (arrRsp[0] == "0")
                        success = true;

            } catch(Exception e)
            {
                Logger.Warn("Exception extracting archive: " +e.Message);
            }
            return success;
        }
开发者ID:DynamicDevices,项目名称:dta,代码行数:30,代码来源:ExtractCommand.cs

示例2: button1_Click

        private void button1_Click(object sender, EventArgs e)
        {
            string host = textBoxServer.Text.Trim();
            string userName = textBoxUserName.Text.Trim();
            string psw = textBoxPassword.Text.Trim();
            string url = textBoxCoomand.Text.Trim();
            string location = @" -P  " + textBoxLocation.Text.Trim();
            string finalCommand = @"wget -bqc '" + url + "' " + location + " ";
            ConnectionInfo conInfo = new ConnectionInfo(host, 22, userName, new AuthenticationMethod[]{
                new PasswordAuthenticationMethod(userName,psw)
            });
            SshClient client = new SshClient(conInfo);
            try
            {
                client.Connect();
                var outptu = client.RunCommand(finalCommand);
            }
            catch (Exception ex)
            {
                textBoxDisplay.Text = ex.Message;
                throw;
            }

            client.Disconnect();
            client.Dispose();
            SetLastValues(host, userName, psw, textBoxLocation.Text.Trim());
        }
开发者ID:amolmore,项目名称:remotewget,代码行数:27,代码来源:RemoteWget.cs

示例3: Run

 public void Run(string cmd, string host)
 {
     try
     {
         using (SshClient c = new SshClient(host, m_userName, m_userPassword))
         {
             Log.DebugFormat("Connecting to {0} with command: {1}", host, cmd );
             c.Connect();
             SshCommand ssh = c.RunCommand(cmd);
             ExitStatus = ssh.ExitStatus;
             Result = ssh.Result;
             c.Disconnect();
             if (Result.Length == 0)
             {
                 Log.DebugFormat("Disconnecting from {0} with exit status: {1} (result is empty)", host, ExitStatus );
             }
             else
             {
                 Log.DebugFormat("Disconnecting from {0} with exit status {1} result is: " + Environment.NewLine + "{2}", host, ExitStatus, Result);
             }
         }
     }
     catch (Exception ex)
     {
         Log.ErrorFormat("Failed to connect to {0} because: {1}", host, ex);
         ExitStatus = -1;
         Result = null;
     }
 }
开发者ID:thayut,项目名称:MultiSessionTool2,代码行数:29,代码来源:RenziImpl.cs

示例4: Run

        public override NodeResult Run()
        {
            if (string.IsNullOrEmpty(host.Value) || string.IsNullOrEmpty(user.Value) || string.IsNullOrEmpty(command.Value))
                return NodeResult.Fail;

            try
            {
                SshClient sshClient = new SshClient(host.Value, port.Value, user.Value, password.Value);
                sshClient.Connect();

                Renci.SshNet.SshCommand sshCommand = sshClient.RunCommand(command.Value);
                Log.Info(sshCommand.CommandText);

                if (!string.IsNullOrWhiteSpace(sshCommand.Result))
                    Log.Warning(sshCommand.Result);
                if (!string.IsNullOrWhiteSpace(sshCommand.Error))
                    Log.Error(sshCommand.Error);
            }
            catch (Exception e)
            {
                Log.Error(e.Message);
                return NodeResult.Fail;
            }

            return NodeResult.Success;
        }
开发者ID:jbatonnet,项目名称:flowtomator,代码行数:26,代码来源:SshCommand.cs

示例5: GetUsers

        public void GetUsers(object sender, BackgroundWorker worker, Delegate sendUsers)
        {
            foreach (string host in SshSettings.Hosts())
            {
                if (worker.CancellationPending)
                    break;

                List<SshUser> users = new List<SshUser>();
                using (SshClient ssh = new SshClient(_currentUser.GetPasswordConenctionInfo(String.Concat(host, SshSettings.Domain))))
                {
                    try
                    {
                        ssh.Connect();
                        string response = ssh.RunCommand("who -u").Execute();
                        // TODO: Parse response.
                        ParseWhoResponse(response, host, ref users);
                        if (users.Count > 0)
                            ((System.Windows.Forms.Form) sender).Invoke(sendUsers, users);
                    }
                    catch (Exception ex)
                    {
                        if (ex is SshException || ex is SocketException)
                        {
                            if (ssh.IsConnected)
                                ssh.Disconnect();
                            ssh.Dispose();
                        }
                        else
                        {
                            throw;
                        }
                    }
                }
            }
        }
开发者ID:WWU-ACM,项目名称:NetworkFriendFinder,代码行数:35,代码来源:SshService.cs

示例6: RebootButton_Click

 protected void RebootButton_Click(object sender, EventArgs e)
 {
     try
     {
         using (var client = new SshClient("ra-jetson.duckdns.org", "ubuntu", "savingL1v3s"))
         {
             client.Connect();
             client.RunCommand("sudo /home/ubuntu/Desktop/bandhan/SQL-Scripts/./RightAlertRemoteRebootIssued-SQL"); // SSH Command Here
             client.RunCommand("sudo reboot"); // SSH Command Here
             client.Disconnect();
         }
     }
     catch (Exception ex)
     {
         Response.Redirect("Down.html");
     }
 }
开发者ID:sbobhate,项目名称:Right-Alert,代码行数:17,代码来源:Alerts.aspx.cs

示例7: UploadFileToFtp

    public String UploadFileToFtp(string url, string filePath)
    {
        try
        {
            var fileName = Path.GetFileName(filePath);
            Console.WriteLine(url);

            var request = (FtpWebRequest)WebRequest.Create(url + fileName);

            request.Method = WebRequestMethods.Ftp.UploadFile;
            request.Credentials = new NetworkCredential("cloudera", "cloudera");
            request.UsePassive = true;
            request.UseBinary = true;
            request.KeepAlive = false;

            using (var fileStream = File.OpenRead(filePath))
            {
                using (var requestStream = request.GetRequestStream())
                {
                    fileStream.CopyTo(requestStream);
                    requestStream.Close();
                }
            }

            var response = (FtpWebResponse)request.GetResponse();
            response.Close();

            Console.WriteLine("Subiendo archivo a hadoop");
            using (var client = new SshClient("192.168.1.6", "cloudera", "cloudera"))

            {
                client.Connect();
                client.RunCommand("hadoop fs -copyFromLocal JSON/" + fileName + " /user/JSON/"+fileName);
                client.RunCommand("rm JSON/" + fileName);
                client.Disconnect();
            }

            return "Archivo Subido con éxito";
        }
        catch (Exception ex)
        {
            return "Parece que tenemos un problema." + ex.Message;
        }
    }
开发者ID:ChichisForever,项目名称:Hadoop,代码行数:44,代码来源:UploadFile.cs

示例8: run

 public void run(string host, string user, string pass, string command)
 {
     using (var sshClient = new SshClient(host, user, pass))
     {
         sshClient.Connect();
         sshClient.RunCommand(command);
         sshClient.Disconnect();
         sshClient.Dispose();
     }
 }
开发者ID:bobcowher,项目名称:SystemRemote1.0,代码行数:10,代码来源:Form1.cs

示例9: beginCracking

        public void beginCracking()
        {
            log("beginning cracking process..");
            var connectionInfo = new PasswordConnectionInfo (xml.Config.host, xml.Config.port, "root", xml.Config.Password);
            using (var sftp = new SftpClient(connectionInfo))
            {
                using (var ssh = new SshClient(connectionInfo))
                {
                    PercentStatus("Establishing SSH connection", 5);
                    ssh.Connect();
                    PercentStatus("Establishing SFTP connection", 10);
                    sftp.Connect();

                    log("Cracking " + ipaInfo.AppName);
                    PercentStatus("Preparing IPA", 25);
                    String ipalocation = AppHelper.extractIPA(ipaInfo);
                    using (var file = File.OpenRead(ipalocation))
                    {
                        log("Uploading IPA to device..");
                        PercentStatus("Uploading IPA", 40);
                        sftp.UploadFile(file, "Upload.ipa");

                    }
                    log("Cracking! (This might take a while)");
                    PercentStatus("Cracking", 50);
                    String binaryLocation = ipaInfo.BinaryLocation.Replace("Payload/", "");
                    String TempDownloadBinary = Path.Combine(AppHelper.GetTemporaryDirectory(), "crackedBinary");
                    var crack = ssh.RunCommand("Clutch -i 'Upload.ipa' " + binaryLocation + " /tmp/crackedBinary");
                    log("Clutch -i 'Upload.ipa' " + binaryLocation + " /tmp/crackedBinary");
                    log("cracking output: " + crack.Result);

                    using (var file = File.OpenWrite(TempDownloadBinary))
                    {
                        log("Downloading cracked binary..");
                        PercentStatus("Downloading cracked binary", 80);
                        try
                        {
                            sftp.DownloadFile("/tmp/crackedBinary", file);
                        }
                        catch (SftpPathNotFoundException e)
                        {
                            log("Could not find file, help!!!!!");
                            return;
                        }
                    }

                    PercentStatus("Repacking IPA", 90);
                    String repack = AppHelper.repack(ipaInfo, TempDownloadBinary);
                    PercentStatus("Done!", 100);

                    log("Cracking completed, file at " + repack);
                }
            }
        }
开发者ID:koufengwei,项目名称:Brake,代码行数:54,代码来源:CrackProcess.cs

示例10: flash_px4

        public static void flash_px4(string firmware_file)
        {
            if (is_solo_alive)
            {
                using (SshClient client = new SshClient("10.1.1.10", 22, "root", "TjSDBkAu"))
                {
                    client.KeepAliveInterval = TimeSpan.FromSeconds(5);
                    client.Connect();

                    if (!client.IsConnected)
                        throw new Exception("Failed to connect ssh");

                    var retcode = client.RunCommand("rm -rf /firmware/loaded");
                    
                    using (ScpClient scpClient = new ScpClient(client.ConnectionInfo))
                    {
                        scpClient.Connect();

                        if (!scpClient.IsConnected)
                            throw new Exception("Failed to connect scp");

                        scpClient.Upload(new FileInfo(firmware_file), "/firmware/" + Path.GetFileName(firmware_file));
                    }

                    var st = client.CreateShellStream("bash", 80, 24, 800, 600, 1024*8);

                    // wait for bash prompt
                    while (!st.DataAvailable)
                        System.Threading.Thread.Sleep(200);

                    st.WriteLine("loadPixhawk.py; exit;");
                    st.Flush();

                    StringBuilder output = new StringBuilder();

                    while (client.IsConnected)
                    {
                        var line = st.Read();
                        Console.Write(line);
                        output.Append(line);
                        System.Threading.Thread.Sleep(100);

                        if (output.ToString().Contains("logout"))
                            break;
                    }
                }
            }
            else
            {
                throw new Exception("Solo is not responding to pings");
            }
        }
开发者ID:ArduPilot,项目名称:MissionPlanner,代码行数:52,代码来源:Solo.cs

示例11: Execute

        /// <summary>
        /// Copy from source to target
        /// </summary>
        /// <param name="client"></param>
        /// <returns></returns>
        public override bool Execute(SshClient client)
        {
            try
            {
                var command1 = client.RunCommand("rm -Rf " + Target);
                return command1.ExitStatus == 0;

            } catch(Exception e)
            {
                Logger.Warn("Exception deleting files: " +e.Message);
            }
            return false;
        }
开发者ID:DynamicDevices,项目名称:dta,代码行数:18,代码来源:DeleteCommand.cs

示例12: Bootstrap

        public object Bootstrap(Drone drone)
        {
            using (var ssh = new SshClient(ChefHost, "root", "0953acb"))
            {
                ssh.Connect();
                var cmd = ssh.RunCommand(string.Format("knife bootstrap {0} -x root -P 0953acb --sudo -N {1} --run-list speedymailer-drone -E xomixfuture", drone.Id, Guid.NewGuid().ToString().Replace("-", "")));   //  very long list
                ssh.Disconnect();

                return new
                {
                    Drone = drone,
                    Data = cmd.Result.Replace("\n", "<br>")
                };
            }
        }
开发者ID:mamluka,项目名称:SpeedyMailer,代码行数:15,代码来源:DronesController.cs

示例13: returnSSH

        private string username = ""; //private store for username and password

        #endregion Fields

        #region Methods

        //Use stored infor to run comamnds on a server
        public string returnSSH(string passedCommand)
        {
            SshClient AuthClient = new SshClient("rcs.rpi.edu", username, password);

            try
            {
                AuthClient.Connect();
                SshCommand RunCommand = AuthClient.RunCommand(passedCommand);
                AuthClient.Disconnect();
                return RunCommand.Result;
            }
            catch
            {
                return "";
            }
        }
开发者ID:daberkow,项目名称:RPI_Helpdesk_pstat,代码行数:23,代码来源:RPI_Auth.cs

示例14: returnSSHFrom

        //Same as returnSSH, but specific a specific server isntead of a the generic RPI server
        public string returnSSHFrom(string passedCommand, string passedServer)
        {
            SshClient AuthClient = new SshClient(passedServer, username, password);

            try
            {
                AuthClient.Connect();
                SshCommand RunCommand = AuthClient.RunCommand(passedCommand);
                AuthClient.Disconnect();
                return RunCommand.Result;
            }
            catch
            {
                return "";
            }
        }
开发者ID:daberkow,项目名称:RPI_Helpdesk_pstat,代码行数:17,代码来源:RPI_Auth.cs

示例15: SendCommand

        public static string SendCommand(string address, string username, string password, string scriptName, string scriptArguments)
        {
            try
            {
                SshClient client = new SshClient(address, username, password);
                client.Connect();
                if (client.IsConnected)
                {
                    client.RunCommand(scriptName + " " + scriptArguments);
                }
                client.Disconnect();
            }
            catch (Exception e)
            {
                return e.Message;
            }

            return null;
        }
开发者ID:aboyce,项目名称:RasPi-Control,代码行数:19,代码来源:SSHController.cs


注:本文中的Renci.SshNet.SshClient.RunCommand方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。