Пример #1
0
        public void Test_Vagrant_Connect()
        {
            SshConnectionInfo input = UserInput;

            SshShell shell = new SshShell(input.Host, input.User);

            if (input.Pass != null)
            {
                shell.Password = input.Pass;
            }
            if (input.IdentityFile != null)
            {
                shell.AddIdentityFile(input.IdentityFile);
            }

            //This statement must be prior to connecting
            shell.RedirectToConsole();

            Console.Write("Connecting...");
            shell.Connect();
            Console.WriteLine("OK");

            // SSH-2.0-OpenSSH_6.6.1p1 Ubuntu-2ubuntu2
            Console.WriteLine("server=" + shell.ServerVersion);

            SshExec shellExec = null;

            if (shell.ShellOpened)
            {
                // shell.Close();

                shellExec = SshExec.Clone(shell);
                // new SshExec(shell.Host, shell.Username, shell.Password);
                shellExec.Connect();
            }

            if (shellExec != null && shellExec.Connected)
            {
                var session = shellExec.Session;
                var channel = shellExec.Channel;
                Console.WriteLine(session);
                Console.WriteLine(channel);

                var stream = shellExec.RunCommandEx("ls -l", true);
                // = shell.StreamASCII();
                while (stream.MoveNext())
                {
                    Console.WriteLine(stream.Current);
                }

                System.Threading.Thread.Sleep(500);
            }

            Console.Write("Disconnecting...");
            if (shellExec != null)
            {
                shellExec.Close();
            }
            Console.WriteLine("OK");
        }
Пример #2
0
        private void backgroundWorkerLog_DoWork(object sender, DoWorkEventArgs e)
        {
            String preStr = "";

            while (true)
            {
                try
                {
                    // 获取日志
                    String   str = exec2.RunCommand("tail -100 /tmp/pppoe.log");
                    String[] opt = GetLastUpdateLog(preStr, str);
                    if (backgroundWorkerLog.CancellationPending)
                    {
                        exec2.Close();
                        break;
                    }
                    this.Invoke(new UpdateLogCallback(UpdateLogContent), new Object[] { opt });
                    preStr = str;
                } catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
                Thread.Sleep(1000);
            }
        }
Пример #3
0
 void Command.issueCommand()
 {
     exec.Connect();
     exec.RunCommand("sudo reboot");
     exec.Close();
     return;
 }
Пример #4
0
        private void btnCMD_Click(object sender, EventArgs ee)
        {
            try
            {
                //  SshConnectionInfo input = Util.GetInput();
                SshExec exec = new SshExec(txtHost.Text, txtUser.Text);
                exec.Password = txtPassword.Text;
                //  if (input.Pass != null) exec.Password = input.Pass;
                //   if (input.IdentityFile != null) exec.AddIdentityFile(input.IdentityFile);

                AppendText("Connecting...");
                exec.Connect();
                AppendText("Connect OK");

                string command = txtCMD.Text;
                if (command != "")
                {
                    exec.RunCommand(command);
                }

                AppendText("Disconnecting...");
                exec.Close();
                AppendText(" Disconnecting OK");
            }
            catch (Exception e)
            {
                AppendText(e.Message);
            }
        }
Пример #5
0
        private string SshExec(string ssh_cmd)
        {
            string  result = "";
            SshExec exec   = SshConnect(ProgramSettings.settings.SshHost, ProgramSettings.settings.SshPort,
                                        ProgramSettings.settings.SshLogin, ProgramSettings.settings.SshPass, ProgramSettings.settings.SshKey);

            result = exec.RunCommand(ssh_cmd).Replace("\n", " ");
            exec.Close();
            return(result);
        }
Пример #6
0
 private void Disconnect()
 {
     if (exec != null)
     {
         if (exec.Connected)
         {
             exec.Close();
         }
     }
 }
Пример #7
0
        public static void syncKioskoLinux(string host, string imageFolder, string videoFolder, string numTienda,
                                           ProgressTaskEventArgs e, int progActual, int razonCambio)
        {
            SshExec exec;
            SshTransferProtocolBase sshCp;

            exec           = new SshExec(host, kioskoUser);
            sshCp          = new Sftp(host, kioskoUser);
            exec.Password  = kioskoPass;
            sshCp.Password = kioskoPass;

            progActual += razonCambio;
            exec.Connect();
            e.UpdateProgress(progActual);

            progActual += razonCambio;
            sshCp.Connect();
            e.UpdateProgress(progActual);

            string imageLocalPath = String.Format("{0}{1}", kioskoRepository, imageFolder);
            string videoLocalPath = String.Format("{0}{1}", kioskoRepository, videoFolder);
            string xmlLocalPath   = String.Format("{0}{1}", pathToTemp, "kioskoXML");

            OneWayFolderSyncSSH imageSync = new OneWayFolderSyncSSH(exec, sshCp, imageLocalPath, kioskoPathToImages);
            OneWayFolderSyncSSH videoSync = new OneWayFolderSyncSSH(exec, sshCp, videoLocalPath, kioskoPathToVideos);
            OneWayFolderSyncSSH xmlSync   = new OneWayFolderSyncSSH(exec, sshCp, xmlLocalPath, kioskoPathToXML);
            XmlKioskoLinux      xmlKiosko = new XmlKioskoLinux(kioskoPathToImages, kioskoPathToVideos, pathToTemp, numTienda, exec);

            progActual += razonCambio * 2;
            imageSync.syncFiles("*.jpg");
            e.UpdateProgress(progActual);

            progActual += razonCambio * 2;
            videoSync.syncFiles("*.flv");
            e.UpdateProgress(progActual);

            progActual += razonCambio;
            xmlKiosko.generateServerXML(host);
            xmlKiosko.generateImageXML();
            xmlKiosko.generateVideoXML();
            e.UpdateProgress(progActual);

            progActual += razonCambio;
            xmlSync.syncFiles("*.xml");
            e.UpdateProgress(progActual);

            progActual += razonCambio;
            exec.Close();
            sshCp.Close();
            e.UpdateProgress(progActual);
        }
Пример #8
0
        public void Start(RemoteDevice target)
        {
            //hacky but openssh seems to ignore signals
            Action start = delegate
            {
                var startexec = new SshExec(target.target.ToString(), target.username, target.password);
                startexec.Connect();
                var result = startexec.RunCommand("mono /root/FlightControl/FlightControl.exe");

                startexec.Close();
            };

            start.Invoke();
        }
Пример #9
0
        private String getMeLastModificationTime(String serverPath)
        {
            String stdOut = null;
            String stdErr = null;
            // need to send following cmd: stat serverPath | grep -E ^M | cut -d' ' -f2
            String cmdToExec = "stat " + serverPath + " | grep -E ^M | cut -d' ' -f2";

            mySshExec = new SshExec(ftpAdr, user, password);
            mySshExec.Connect();
            mySshExec.RunCommand(cmdToExec, ref stdOut, ref stdErr);
            mySshExec.Close();
            //Debug.Print("Data pliku na serwerze " + stdOut);
            return(stdOut);
        }
Пример #10
0
        public override DTSExecResult Execute(Connections connections, VariableDispenser variableDispenser, IDTSComponentEvents componentEvents, IDTSLogging log, object transaction)
        {
            ConnectionManager conn = getCurrentConnectionManager(connections);
            List <KeyValuePair <string, string> > connParams = (List <KeyValuePair <string, string> >)conn.AcquireConnection(transaction);

            string host     = connParams.Find(t => t.Key == "Host").Value;
            string username = connParams.Find(t => t.Key == "Username").Value;
            string password = connParams.Find(t => t.Key == "Password").Value;
            int    port     = Convert.ToInt32(connParams.Find(t => t.Key == "Port").Value);

            SshExec exec = new SshExec(host, username);

            exec.Password = password;

            try
            {
                string stdOut = string.Empty;
                string stdErr = string.Empty;
                exec.Connect();
                StringReader sr = new StringReader(_commandText);
                while (true)
                {
                    string s = sr.ReadLine();
                    if (s != null && stdErr.Trim().Length == 0)
                    {
                        int res = exec.RunCommand(s, ref stdOut, ref stdErr);
                    }
                    else
                    {
                        if (stdErr.Trim().Length > 0)
                        {
                            fireError(componentEvents, stdErr);
                            return(DTSExecResult.Failure);
                        }
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                fireError(componentEvents, ex.Message);
                return(DTSExecResult.Failure);
            }
            finally
            {
                exec.Close();
            }
            return(DTSExecResult.Success);
        }
Пример #11
0
        private string runStatusCommand(SshShell shell, SshExec exec, string command)
        {
            string stdout = "";
            string stderr = "";

            shell.Connect();
            shell.RedirectToConsole();
            exec.Connect();

            int ret = exec.RunCommand(command, ref stdout, ref stderr);

            exec.Close();
            shell.Close();
            return(stdout);
        }
Пример #12
0
        public void Kill(RemoteDevice target)
        {
            //hacky but openssh seems to ignore signals
            Action kill = delegate
            {
                var killExec = new SshExec(target.target.ToString(), target.username, target.password);
                killExec.Connect();
                var killcmd = @"killall mono";
                var result  = killExec.RunCommand(killcmd);
                result = killExec.RunCommand("killall FCRestarter");
                killExec.Close();
            };

            kill.Invoke();
        }
Пример #13
0
 private void TestConnection()
 {
     try
     {
         SshExec exec = WgetDownload.SshConnect(txtSshHost.Text, int.Parse(txtSshPort.Text), txtSshLogin.Text,
                                                txtSshPass.Text, txtSshKey.Text);
         string server = exec.ServerVersion;
         exec.Close();
         MessageBox.Show(Localization.GetString("Ok") + "\r\n" + server, Localization.GetString("TestConnection"), MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, Localization.GetString("TestConnection"), MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
Пример #14
0
        public void runCommand(string command, string stdout = "", string stderr = "")
        {
            _shell.Connect();
            _shell.RedirectToConsole();
            _exec.Connect();

            int ret = _exec.RunCommand(command, ref stdout, ref stderr);

            if (ret != 0)
            {
                System.Diagnostics.Debugger.Break();
            }

            _exec.Close();
            _shell.Close();
        }
Пример #15
0
        public void RunShellTest()
        {
            try
            {
                shell.Connect();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            shell.ExpectPattern = "#";
            Console.WriteLine(shell.Expect());
            shell.WriteLine(@"ls");
            Console.WriteLine(shell.Expect());
            shell.WriteLine(@"ll");
            Console.WriteLine(shell.Expect());
            shell.WriteLine(@"cd /usr/local");
            Console.WriteLine(shell.Expect());
            shell.WriteLine(@"ll");
            Console.WriteLine(shell.Expect());
            shell.WriteLine(@"topp");
            Console.WriteLine(shell.Expect());

            shell.Close();


            Console.WriteLine("----------------------------------------------");

            exec.Connect();
            string strRrr = "";
            string strOut = "";

            exec.RunCommand("ls", ref strOut, ref strRrr);
            System.Threading.Thread.Sleep(1000);
            Console.WriteLine(strOut);
            Console.WriteLine(strRrr);

            exec.RunCommand(@"cd /usr/local", ref strOut, ref strRrr);
            Console.WriteLine(strOut);
            Console.WriteLine(strRrr);


            Console.WriteLine(exec.RunCommand(@"ll"));
            Console.WriteLine(exec.RunCommand(@"cd /usr/local"));

            exec.Close();
        }
Пример #16
0
        // This should only be run for sequencing jobs, i.e. those requiring PhRed validation.
        // run phred
        private void RunPhred(int barcode)
        {
            // list of commands to execute
            // cp -R /mnt/cgfdata/raw/{barcode} /home/caesdev/raw
            // mkdir /home/caesdev/output/{barcode}
            // /opt/pkg/genome/bin/phred -id /home/caesdev/raw/{barcode} -qd /home/caesdev/output/{barcode}
            // cp -R /home/caesdev/output/{barcode} /mnt/cgfdata/output

            string output = null, error = null;

            var ssh = new SshExec(PhredServer, PhredUsername, PhredPassword);

            ssh.Connect();

            try
            {
                // copy in data
                //ssh.RunCommand(string.Format(@"cp -R /mnt/cgfdata/raw/{0} /home/{1}/raw", barcode, PhredUsername));
                ssh.RunCommand(string.Format(@"cp -R /mnt/cgfdata/Backup/raw/{0} /home/{1}/raw", barcode, PhredUsername));
                ssh.RunCommand(string.Format(@"mkdir /home/{0}/output/{1}", PhredUsername, barcode));

                // execute
                ssh.RunCommand(string.Format(@"/opt/pkg/genome/bin/phred -id /home/{0}/raw/{1} -qd /home/{0}/output/{1}", PhredUsername, barcode), ref output, ref error);

                if (!string.IsNullOrEmpty(error))
                {
                    throw new Exception(error);
                }

                // clean up
                //ssh.RunCommand(string.Format(@"mv /home/{0}/output/{1} /mnt/cgfdata/output", PhredUsername, barcode));
                ssh.RunCommand(string.Format(@"mv /home/{0}/output/{1} /mnt/cgfdata/Backup/output", PhredUsername, barcode));
                ssh.RunCommand(string.Format(@"rm /home/{0}/raw/{1}/*", PhredUsername, barcode));
                ssh.RunCommand(string.Format(@"rmdir /home/{0}/raw/{1}", PhredUsername, barcode));
            }
            catch
            {
                // automatic cleanup
                ssh.RunCommand(string.Format(@"rm /home/{0}/output/{1}/*", PhredUsername, barcode));
                ssh.RunCommand(string.Format(@"rmdir /home/{0}/output/{1}", PhredUsername, barcode));
                ssh.RunCommand(string.Format(@"rm /home/{0}/raw/{1}/*", PhredUsername, barcode));
                ssh.RunCommand(string.Format(@"rmdir /home/{0}/raw/{1}", PhredUsername, barcode));
            }

            ssh.Close();
        }
Пример #17
0
        public void Test_Vagrant_ls()
        {
            SshConnectionInfo input = UserInput;

            SshExec exec = new SshExec(input.Host, input.User);

            if (input.Pass != null)
            {
                exec.Password = input.Pass;
            }
            // if(input.IdentityFile != null) exec.AddIdentityFile( input.IdentityFile );

            Console.Write("Connecting...");
            exec.Connect();
            Console.WriteLine("OK");

            // while
            {
                Console.Write("Enter a command to execute ['Enter' to cancel]: ");
                string command = "ls";

                Console.WriteLine(command);

                var outputEnum = exec.RunCommandEx(command, false); // .RunCommand(command);
                while (outputEnum.MoveNext())
                {
                    Console.WriteLine(outputEnum.Current);
                }
            }

            SFTPUtil util = SFTPUtil.Clone(exec);

            var list = util.ListFiles("/");

            foreach (ChannelSftp.LsEntry line in list)
            {
                Console.WriteLine(line.Filename);
            }

            Console.Write("Disconnecting...");

            util.Dispose();
            exec.Close();
            Console.WriteLine("OK");
        }
        public static SshRemoteProcess CreateProcess(MeeGoExecutionCommand cmd, string sdbOptions, MeeGoDevice device,
                                                     Dictionary <string, string> xauth,
                                                     Action <string> stdOut, Action <string> stdErr)
        {
            string exec = GetCommandString(cmd, sdbOptions, xauth);

            var ssh = new LiveSshExec(device.Address, device.Username, device.Password);

            //hacky but openssh seems to ignore signals
            Action kill = delegate {
                var killExec = new SshExec(device.Address, device.Username, device.Password);
                killExec.Connect();
                killExec.RunCommand("ps x | grep '" + cmd.DeviceExePath + "' | " +
                                    "grep -v 'grep \\'" + cmd.DeviceExePath + "\\' | awk '{ print $1 }' | xargs kill ");
                killExec.Close();
            };

            return(new SshRemoteProcess(ssh, exec, stdOut, stdErr, kill));
        }
Пример #19
0
        public static void ExecuteSingleCommand(string command)
        {
            try
            {
                //create a new ssh stream
                SshExec ssh = new SshExec(MACHINE_IP, USER_NAME, PASSWORD);

                ssh.Connect();

                //writing to the ssh channel
                var str = ssh.RunCommand(command);

                ssh.Close();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
Пример #20
0
        //WPF로 파일 업로드 (localfile : 컴퓨터 파일 경로, hwak : 확장자, std_no : 학번)
        //설치 순서 주의! - packages폴더에 dll이 있어야함.
        //사용시 https://sourceforge.net/projects/sharpssh/ 에서 다운한 파일 중 'Tamir.SharpSSH.dll'을 참조 후 누겟의 Tamir.SharpSSH 설치, 그 후 앞서 참조한 dll 참조 지우기
        private void Uploadimg(string localfile, string hwak, string std_no)
        {
            Sftp oSftp = null;

            try
            {
                SshExec se = new SshExec("l.bsks.ac.kr", "p201606023", "pp201606023");
                se.Connect(22);
                string dir = "/home/p201606023/public_html/image/";
                se.RunCommand("rm " + dir + std_no + ".jpg");
                se.RunCommand("rm " + dir + std_no + ".jpeg");
                se.RunCommand("rm " + dir + std_no + ".png");
                se.RunCommand("rm " + dir + std_no + ".gif");
                se.RunCommand("rm " + dir + std_no + ".JPG");
                se.RunCommand("rm " + dir + std_no + ".PNG");
                se.RunCommand("rm " + dir + std_no + ".GIF");
                se.Close();

                string _ftpURL       = "l.bsks.ac.kr";                        //Host URL or address of the SFTP server
                string _UserName     = "******";                          //User Name of the SFTP server
                string _Password     = "******";                         //Password of the SFTP server
                int    _Port         = 22;                                    //Port No of the SFTP server (if any)
                string _ftpDirectory = "/home/p201606023/public_html/image/"; //The directory in SFTP server where the files will be uploaded

                oSftp = new Sftp(_ftpURL, _UserName, _Password);
                oSftp.Connect(_Port);

                oSftp.Put(localfile, _ftpDirectory + std_no + "." + hwak);
            }
            catch (Exception ex)
            {
                MessageBox.Show("이미지 저장에 실패하였습니다.\n" + ex.Message + "::" + ex.StackTrace, "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);

                return;
            }
            finally
            {
                if (oSftp != null)
                {
                    oSftp.Close();
                }
            }
        }
Пример #21
0
        public override void ProcessCommand(OSAEMethod method)
        {
            try
            {
                string[] tmp = method.Parameter1.Split('/');
                server   = tmp[0];
                username = tmp[1];
                password = tmp[2];
                string command = method.Parameter2;
                Log.Debug("Sending command: " + command + " | " + server + " | " + username + " | " + password);
                SshExec ssh = new SshExec(server, username, password);
                ssh.Connect();

                string response = ssh.RunCommand(command);
                Log.Debug("Response: " + response);
                ssh.Close();
            }
            catch (Exception ex)
            { Log.Error("Error Sending command", ex); }
        }
Пример #22
0
        private void Form1_Load(object sender, EventArgs e)
        {
            try
            {
                SshExec shell = new SshExec(ADDRESS_SERVEUR_TELNET, LOGIN_SERVEUR_TELNET, PASSWD_SERVEUR_TELNET);

                ShellBox.AppendText("Connecting...\n");

                shell.Connect();

                if (shell.Connected == true)
                {
                    ShellBox.AppendText("Connexion OK\n");

                    //while (true)
                    //{
                    System.Threading.Thread.Sleep(500);
                    string output = shell.RunCommand(@"tail -f \gsoap\log\VSSrvConnexionGS.log");
                    ShellBox.AppendText(output + "\n");
                    //}
                    ShellBox.AppendText("Disconnecting...\n");
                    shell.Close();
                    if (shell.Connected == false)
                    {
                        ShellBox.AppendText("Deconnexion OK\n");
                    }
                    else
                    {
                        ShellBox.AppendText("Deconnexion KO\n");
                    }
                }
                else
                {
                    ShellBox.AppendText("Connexion KO\n");
                }
            }
            catch (Exception exc)
            {
                MessageBox.Show(exc.Message);
            }
        }
Пример #23
0
 public void Run()
 {
     try
     {
         SshConnectionInfo input = Util.GetInput();
         exec = new SshExec(input.Host, input.User);
         if (input.Pass != null)
         {
             exec.Password = input.Pass;
         }
         exec.Connect();
         string command = Console.ReadLine();
         string output  = exec.RunCommand(command);
         Console.WriteLine(output);
         exec.Close();
     }
     catch (Exception e)
     {
         Console.WriteLine(e.Message);
     }
 }
Пример #24
0
        public static void RunExample()
        {
            SshConnectionInfo input = Util.GetInput();

            try
            {
                SshExec exec = new SshExec(input.Host, input.User);
                if (input.Pass != null)
                {
                    exec.Password = input.Pass;
                }
                if (input.IdentityFile != null)
                {
                    exec.AddIdentityFile(input.IdentityFile);
                }

                Console.Write("Connecting...");
                exec.Connect();
                Console.WriteLine("OK");
                while (true)
                {
                    Console.Write("Enter a command to execute ['Enter' to cancel]: ");
                    string command = Console.ReadLine();
                    if (command == "")
                    {
                        break;
                    }
                    string output = exec.RunCommand(command);
                    Console.WriteLine(output);
                }
                Console.Write("Disconnecting...");
                exec.Close();
                Console.WriteLine("OK");
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
Пример #25
0
        public override void ProcessCommand(OSAEMethod method)
        {
            try
            {
                string[] tmp = method.Parameter1.Split('/');
                server   = tmp[0];
                username = tmp[1];
                password = tmp[2];
                string command = method.Parameter2;
                logging.AddToLog("Sending command: " + command + " | " + server + " | " + username + " | " + password, false);
                SshExec ssh = new SshExec(server, username, password);
                ssh.Connect();

                string response = ssh.RunCommand(command);
                logging.AddToLog("Response: " + response, false);
                ssh.Close();
            }
            catch (Exception ex)
            {
                logging.AddToLog("Error Sending command - " + ex.Message + " -" + ex.InnerException, true);
            }
        }
Пример #26
0
        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 < m.Length; i++)
                    {
                        Console.WriteLine(m[i]);
                    }
                }
                Console.Write("Disconnecting...");
                exec.Close();
                Console.WriteLine("OK");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Пример #27
0
        public bool Test()
        {
            bool    result = false;
            SshExec exec   = new SshExec(host, username);

            // SshShell exec = new SshShell(host, username);
            try
            {
                exec.Password = password;
                if (!string.IsNullOrEmpty(pkFile))
                {
                    exec.AddIdentityFile(pkFile);
                }
                exec.Connect();
                string output = exec.RunCommand(commandText);
                Console.WriteLine(output);
                result = true;
            }
            catch (Exception)
            {
                result = false;
            }
            finally
            {
                try
                {
                    if (exec != null && exec.Connected)
                    {
                        exec.Close();
                    }
                }
                catch
                {
                }
            }
            return(result);
        }
Пример #28
0
 private void backgroundWorkerStatus_DoWork(object sender, DoWorkEventArgs e)
 {
     while (true)
     {
         try
         {
             // 获取接口状态
             String uciCom = exec.RunCommand("uci show network | grep -E \"(network\\.)\\w+(\\.proto='pppoe')\" | cut -d . -f 2");
             ifList = uciCom.Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries);
             List <InterfaceStatus> list = new List <InterfaceStatus>();
             foreach (String ifname in ifList)
             {
                 String          eth = exec.RunCommand("uci show network." + ifname + ".ifname | cut -d = -f 2 | cut -d \\' -f 2");
                 String          res = exec.RunCommand("ifconfig | grep pppoe-" + ifname);
                 InterfaceStatus ifs = new InterfaceStatus(ifname, false);
                 ifs.Eth = eth;
                 if (!res.Trim().Equals(""))
                 {
                     String user = exec.RunCommand("uci show network." + ifname + ".username | cut -d = -f 2 | cut -c 13-23");
                     ifs.UserName = user;
                     ifs.OnLine   = true;
                 }
                 list.Add(ifs);
             }
             if (backgroundWorkerStatus.CancellationPending)
             {
                 exec.Close();
                 break;
             }
             this.Invoke(new UpdateInterfaceStatucCallback(UpdateInterfaceStatus), list);
         } catch (Exception ex)
         {
             Console.WriteLine(ex.Message);
         }
         Thread.Sleep(1000);
     }
 }
Пример #29
0
        public void ProcessCommand(System.Data.DataTable table)
        {
            System.Data.DataRow row = table.Rows[0];
            //process command
            try
            {
                string[] tmp = row["parameter_1"].ToString().Split('/');
                server   = tmp[0];
                username = tmp[1];
                password = tmp[2];
                string command = row["parameter_2"].ToString();
                osae.AddToLog("Sending command: " + command + " | " + server + " | " + username + " | " + password, false);
                SshExec ssh = new SshExec(server, username, password);
                ssh.Connect();

                string response = ssh.RunCommand(command);
                osae.AddToLog("Response: " + response, false);
                ssh.Close();
            }
            catch (Exception ex)
            {
                osae.AddToLog("Error Sending command - " + ex.Message + " -" + ex.InnerException, true);
            }
        }
Пример #30
0
 private static void CloseSshConnection()
 {
     sftpBase.Close();
     ssh.Close();
 }