Esempio n. 1
0
        public static SshExec SshConnect(string ssh_host, int ssh_port, string ssh_login, string ssh_pass, string ssh_key)
        {
            SshExec exec = null;

            if (ssh_key.Length == 0)
            {
                exec = new SshExec(ssh_host, ssh_login, ssh_pass);
            }
            else
            {
                try
                {
                    exec = new SshExec(ssh_host, ssh_login);
                    if (ssh_pass.Length == 0)
                    {
                        exec.AddIdentityFile(ssh_key);
                    }
                    else
                    {
                        exec.AddIdentityFile(ssh_key, ssh_pass);
                    }
                }
                catch { }
            }
            exec.Connect(ssh_port);
            return(exec);
        }
Esempio n. 2
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");
        }
        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);
            }
        }
Esempio n. 4
0
        public void ExecuteCommand(String command)
        {
            using (var ssh = new SshExec(host, user, pass))
            {
                ssh.Connect();

                ssh.RunCommand(command);
            }
        }
Esempio n. 5
0
        public void ExecuteCommand(String command)
        {
            using (var ssh = new SshExec(host, user, pass))
            {
                ssh.Connect();

                ssh.RunCommand(command);
            }
        }
Esempio n. 6
0
        public XmlKioskoLinux(string imgFolder, string videoFolder, string tempFileFolder, string numTienda, SshExec exec)
        {
            this.imgFolder      = imgFolder;
            this.videoFolder    = videoFolder;
            this.tempFileFolder = tempFileFolder;
            this.numTienda      = numTienda;
            this.exec           = exec;

            initVars();
        }
Esempio n. 7
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);
        }
Esempio n. 8
0
 /* Constructor */
 public Reboot(RaspberryPi pi)
 {
     try
     {
         this.pi            = pi;
         this.exec          = new SshExec(pi.getHostname(), pi.getUser());
         this.exec.Password = pi.getPassword();
     }
     catch (Exception) { }
 }
Esempio n. 9
0
        protected long CaptureEnclosureInfo(string _host, SshExec oSSH)
        {
            try
            {
                string strOutput        = "";
                string strEnclosureName = "";
                string strEnclosureType = "";
                string strSerialNumber  = "";
                string strUUID          = "";
                string strAssetTag      = "";

                strSSHCommand = "show enclosure info";
                strOutput     = runSSHCommand(_host, oSSH, strSSHCommand);
                foreach (DataRow dr in dtEncInfoAttributes.Rows)
                {
                    switch (Int32.Parse(dr["id"].ToString()))
                    {
                    case 1:
                        strEnclosureName = getSSHCommandAttributeValue(strOutput, dr["Attribute"].ToString(),
                                                                       dr["ContentSearchStartSection"].ToString(), dr["ContentSearchEndSection"].ToString());
                        break;

                    case 2:
                        strEnclosureType = getSSHCommandAttributeValue(strOutput, dr["Attribute"].ToString(),
                                                                       dr["ContentSearchStartSection"].ToString(), dr["ContentSearchEndSection"].ToString());
                        break;

                    case 3:
                        strSerialNumber = getSSHCommandAttributeValue(strOutput, dr["Attribute"].ToString(),
                                                                      dr["ContentSearchStartSection"].ToString(), dr["ContentSearchEndSection"].ToString());
                        break;

                    case 4:
                        strUUID = getSSHCommandAttributeValue(strOutput, dr["Attribute"].ToString(),
                                                              dr["ContentSearchStartSection"].ToString(), dr["ContentSearchEndSection"].ToString());
                        break;

                    case 5:
                        strAssetTag = getSSHCommandAttributeValue(strOutput, dr["Attribute"].ToString(),
                                                                  dr["ContentSearchStartSection"].ToString(), dr["ContentSearchEndSection"].ToString());
                        break;
                    }
                }

                return(AddEnclosureInfo(strEnclosureName, strEnclosureType, strSerialNumber, strAssetTag, _host, strUUID));
            }
            catch (Exception ex)
            {
                strErrorMsg = "Host Name :" + _host + "\r\n";
                strErrorMsg = strErrorMsg + strSSHCommand + "\r\n";

                boolErrorOccured = true;
                throw new Exception(strErrorMsg + ex.Message);
            }
        }
Esempio n. 10
0
        public OneWayFolderSyncSSH(SshExec exec, SshTransferProtocolBase sshCp, string localFolder, string remoteFolder)
        {
            this.localFolder  = localFolder;
            this.remoteFolder = remoteFolder;

            this.localFiles  = new ArrayList();
            this.remoteFiles = new ArrayList();

            this.exec  = exec;
            this.sshCp = sshCp;
        }
Esempio n. 11
0
        }     // end EjecutarSHH

        public static string test()
        {
            //Establecemos la conexión SSH
            const string host    = "tmpsao445674";
            SshExec      sshExec = new SshExec(host, "tomcat", "XXXsrivera445674");

            sshExec.Connect();

            string result = sshExec.RunCommand(@"cat /etc/redis.conf");

            return(result);
        }
Esempio n. 12
0
        private static void OpenSshConnection()
        {
            ssh = new SshExec(host, user, password);
            ssh.Connect(sshPort);
            Console.WriteLine("Connected");

            sftpBase = new Tamir.SharpSsh.Sftp(host, user, password);
            sftpBase.OnTransferStart += new FileTransferEvent(sftpBase_OnTransferStart);
            sftpBase.OnTransferEnd   += new FileTransferEvent(sftpBase_OnTransferEnd);
            Console.WriteLine("Trying to Open Connection...");
            sftpBase.Connect(sshPort);
            Console.WriteLine("Connected Successfully !");
        }
Esempio n. 13
0
 public SSHOperation(string DDEI_IP, string SSH_ROOT, string SSH_PASS)
 {
     shell = new SshExec(DDEI_IP, SSH_ROOT, SSH_PASS);
     try
     {
         shell.Connect();
     }
     catch (Exception e)
     {
         Console.WriteLine("Error happened when SSH connect to DDEI! [{0}]", e.Message);
         throw new Exception("SSH connection fail!");
     }
 }
Esempio n. 14
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);
        }
Esempio n. 15
0
        public XmlKioskoLinux(string imgFolder, string videoFolder, string tempFileFolder, string numTienda, string host, string user, string password)
        {
            this.imgFolder      = imgFolder;
            this.videoFolder    = videoFolder;
            this.tempFileFolder = tempFileFolder;
            this.numTienda      = numTienda;


            exec          = new SshExec(host, user);
            exec.Password = password;
            exec.Connect();

            initVars();
        }
        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);
        }
Esempio n. 17
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();
        }
Esempio n. 18
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);
        }
Esempio n. 19
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();
        }
Esempio n. 20
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);
     }
 }
Esempio n. 21
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);
        }
Esempio n. 22
0
        public void CheckJobStatus()
        {
            string stdout = "";
            //string stderr = "";
            bool     atleastOne = false;
            SshShell shell      = new SshShell(Consts.DEFAULT_HOST, Consts.DEFAULT_USERNAME, Consts.DEFAULT_PASSWORD);
            SshExec  exec       = new SshExec(Consts.DEFAULT_HOST, Consts.DEFAULT_USERNAME, Consts.DEFAULT_PASSWORD);

            Thread.Sleep(1000);

            string jobId;
            int    runningJobs = 0;

            while (!atleastOne || runningJobs != 0)
            {
                stdout      = runStatusCommand(shell, exec, "mapred job -list");
                runningJobs = Int32.Parse(stdout.Split(null).ToList()[0]);

                if (runningJobs != 0)
                {
                    atleastOne = true;
                    jobId      = stdout.Split(null).ToList().Where(line => line.Contains("job_")).First();

                    double map;
                    double reduce;
                    while (true)
                    {
                        stdout = runStatusCommand(shell, exec, $"mapred job -status {jobId}");
                        map    = Double.Parse((stdout.Split('\n').Where(line =>
                                                                        line.Contains("map()")).First().ToString()).Split(null)[2]) * 100;
                        reduce = Double.Parse((stdout.Split('\n').Where(line =>
                                                                        line.Contains("reduce()")).First().ToString()).Split(null)[2]) * 100;

                        StatusModel.Instance.setProgress((int)((reduce + map) / 2), 100);
                        StatusModel.Instance.Status = $"Map {(int)map}% - Reduce {(int)reduce}%";
                        if (reduce == 100)
                        {
                            break;
                        }
                        Thread.Sleep(500);
                    }
                }
            }

            StatusModel.Instance.Status = "Finished MapReduce!";
        }
Esempio n. 23
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();
        }
Esempio n. 24
0
        public OneWayFolderSyncSSH(string host, string user, string password, string localFolder, string remoteFolder)
        {
            this.localFolder  = localFolder;
            this.remoteFolder = remoteFolder;

            this.localFiles  = new ArrayList();
            this.remoteFiles = new ArrayList();

            exec  = new SshExec(host, user);
            sshCp = new Tamir.SharpSsh.Sftp(host, user);

            exec.Password  = password;
            sshCp.Password = password;

            exec.Connect();
            sshCp.Connect();
        }
Esempio n. 25
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");
        }
Esempio n. 26
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);
            }
        }
Esempio n. 27
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();
                }
            }
        }
        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));
        }
Esempio n. 29
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); }
        }
Esempio n. 30
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);
            }
        }
Esempio n. 31
0
        public static bool InitSSH()
        {
            bool yes = false;

            if (LoadSettings())
            {
                SshExec exec = new SshExec(SshSettings.server, SshSettings.user);
                sshexec = exec;

                SshTransferProtocolBase sshCp = new Scp(SshSettings.server, SshSettings.user);
                //А можно и так
                //sshCp = new Sftp(input.Host, input.User);
                sshsess = sshCp;
                yes     = true;
            }
            else
            {
                yes = false;
            }
            return(yes);
        }