Example #1
0
        public static string EjecutarSSH(string pServidor, string pUsuario, string pPassword, string pComando)
        {
            SshStream SSH = null;

            try
            {
                // instancia del objeto SSHShell
                SSH = new SshStream(pServidor, pUsuario, pPassword);
                // ejecutar el comando
                SSH.Write(pComando);

                string ret = SSH.ReadResponse();
                // confirmar
                SSH.Flush();

                return(ret);
            }
            catch (Exception ex)
            { throw ex; }
            finally
            {
                //cerrar conexion SSH
                SSH.Close();
            } // end try
        }     // end EjecutarSHH
Example #2
0
 public static void MakeNewDirectory(string dirName)
 {
     //create a new ssh stream
     using (SshStream ssh = new SshStream(MACHINE_IP, USER_NAME, PASSWORD))
     {
         //writing to the ssh channel
         ssh.Write("mkdir " + dirName);
     }
 }
 public string Connect(string host, string username, string password)
 {
     _sshStream = new SshStream(host, username, password)
                      {
                          RemoveTerminalEmulationCharacters = true,
                          Prompt = @"\[[^@]*@[^]]*]\s>\s?$"
                      };
     return _sshStream.ReadResponse();
 }
Example #4
0
 public void SSH_Connect(string IP)
 {
     this.ssh_rx = new SshStream(IP, "root", "fiskopter348");
     this.ssh_rx.Write("stty -F /dev/ttyUSB0 sane raw -echo -echoe -echok 115200");
     this.ssh_rx.Write("echo \"PC_Connected_to_Fiscopter\n\" > /dev/ttyUSB0");
     this.ssh_rx.Write("cat /dev/ttyUSB0");
     MessageBox.Show(this.ssh_rx.ReadResponse());
     this.ssh_rx.BeginRead(rx_buff, 0, rx_buff.Length, rx_clbk, new object());
 }
Example #5
0
 public void ssh_command(string type, string host, string user, string password, string command)
 {
     if (type == "list dir")
     {
         Sftp sftp = new Sftp(host, user, password);
         try
         {
             sftp.Connect();
             ArrayList analyses = sftp.GetFileList(command);
             if (analyses.Count > 0)
             {
                 foreach (string run in analyses)
                 {
                     if (run.Length > 10)
                     {
                         this.stdRunsList.Items.Add(run);
                     }
                 }
                 count_label.Text = "Count: " + stdRunsList.Items.Count.ToString();
                 connected();
             }
         }
         catch
         {
             ConnectionError.Visible = true;
             pwdBox.ResetText();
         }
         finally
         {
             sftp.Close();
         }
     }
     else if (type == "kill")
     {
         ssh.Write(command);
         terminalThread.CancelAsync();
     }
     else
     {
         try
         {
             ssh   = new SshStream(host, user, password);
             abort = false;
             stopWatch.Start();
             terminalThread.RunWorkerAsync();
             checkThread.RunWorkerAsync();
             ssh.Write(command);
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message, "Minion - Stream Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
     }
 }
Example #6
0
        private void RebButton_Click(object sender, EventArgs e)
        {
            DialogResult Result = MessageBox.Show("Are you sure you wish to reboot?", "Warning", MessageBoxButtons.YesNo);

            if (Result == DialogResult.Yes)
            {
                host = DefaultIP.Text;
                SshStream ssh     = new SshStream(host, user, pass);
                string    command = "reboot";
                ssh.Write(command);
            }
        }
Example #7
0
        private void btnStartPointsat_Click(object sender, EventArgs e)
        {
            ssh = new SshStream(txtIP.Text, txtUsername.Text, txtPassword.Text);
            ssh.Write("cd svs");

            ReadSSH();
            ssh.Write("export LD_LIBRARY_PATH=/svs/libs");

            ReadSSH();

            ssh.Write("./pointsat_core&");
            ReadSSH();
        }
Example #8
0
        private void btnConnect_Click(object sender, EventArgs e)
        {
            try
            {
                ssh = new SshStream(txtIP.Text, txtUsername.Text, txtPassword.Text);

                txtConsole.Text  = string.Format("OK ({0}/{1})", ssh.Cipher, ssh.Mac) + Environment.NewLine;
                txtConsole.Text += string.Format("Server version={0}, Client version={1}", ssh.ServerVersion, ssh.ClientVersion) + Environment.NewLine;
                txtConsole.Text += string.Format("-Use the 'exit' command to disconnect.");
            }
            catch (Exception exc)
            {
                txtConsole.Text += exc.ToString();
            }
        }
Example #9
0
        /// <summary>
        /// Demonstrates the SshStream class
        /// </summary>
        public static void SshStream()
        {
            GetInput();

            try
            {
                Console.Write("-Connecting...");
                SshStream ssh = new SshStream(host, user, pass);
                Console.WriteLine("OK ({0}/{1})", ssh.Cipher, ssh.Mac);
                Console.WriteLine("Server version={0}, Client version={1}", ssh.ServerVersion, ssh.ClientVersion);
                Console.WriteLine("-Use the 'exit' command to disconnect.");
                Console.WriteLine();

                //Sets the end of response character
                ssh.Prompt = "#";
                //Remove terminal emulation characters
                ssh.RemoveTerminalEmulationCharacters = true;

                //Reads the initial response from the SSH stream
                Console.Write(ssh.ReadResponse());

                //Send commands from the user
                while (true)
                {
                    string command = Console.ReadLine();
                    if (command.ToLower().Equals("exit"))
                    {
                        break;
                    }

                    //Write command to the SSH stream
                    ssh.Write(command);
                    //Read response from the SSH stream
                    Console.Write(ssh.ReadResponse());
                }
                ssh.Close();                 //Close the connection
                Console.WriteLine("Connection closed.");
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
Example #10
0
 public void SSH_Connect(string IP)
 {
     this.ssh_tx = new SshStream(IP, "root", "fiskopter348");
     this.ssh_tx.Write("stty -F /dev/ttyUSB0 sane raw -echo -echoe -echok 115200");
 }
Example #11
0
        public Int32 BarCodeImageCreate(string PinCode, int OrderSeq)
        {
            try
            {
                Int32  Result   = 0;
                string makefile = HKLibrary.UTIL.HKFileHelper.GetCurrentDirectory();
                string sDirPath;
                sDirPath = makefile + "\\data";
                DirectoryInfo di = new DirectoryInfo(sDirPath);
                if (di.Exists == false)
                {
                    di.Create();
                }

                makefile += "\\";
                makefile += "data";
                makefile += "\\";
                makefile += PinCode;
                makefile += ".jpg";

                string folderName  = Convert.ToString(OrderSeq);
                string ftpfileName = folderName + "/" + PinCode + ".jpg";

                string ftpBasicPath = "/var/www/IMAGE/Web/upload/order/barcode/";


                BarcodeLib.Barcode b = new BarcodeLib.Barcode();
                b.Encode(BarcodeLib.TYPE.CODE128, PinCode);
                b.SaveImage(makefile, BarcodeLib.SaveTypes.JPG);

                //string ftpUri = "" + ftpBasicPath + folderName;
                SshStream ssh = new SshStream("ftp://ledev.leisureq.co.kr:10004/", "lion", "gkffl1!");



                string        ftpUri  = "ftp://121.78.127.40:21/" + ftpBasicPath + folderName;
                FtpWebRequest request = (FtpWebRequest)WebRequest.Create(ftpUri);
                request.Method = WebRequestMethods.Ftp.MakeDirectory;
                //request.Method = WebRequestMethods.Ftp.UploadFile;

                // This example assumes the FTP site uses anonymous logon.
                request.Credentials = new NetworkCredential("infobay", "info9887");
                FtpWebResponse response  = (FtpWebResponse)request.GetResponse();
                Stream         ftpStream = response.GetResponseStream();

                ftpStream.Close();
                response.Close();

                ftpUri         = "ftp://121.78.127.40:21/" + ftpBasicPath + ftpfileName;
                request        = (FtpWebRequest)WebRequest.Create(ftpUri);
                request.Method = WebRequestMethods.Ftp.UploadFile;

                // This example assumes the FTP site uses anonymous logon.
                request.Credentials = new NetworkCredential("infobay", "info9887");
                byte[] fileContents = File.ReadAllBytes(makefile);
                request.ContentLength = fileContents.Length;

                Stream requestStream = request.GetRequestStream();
                requestStream.Write(fileContents, 0, fileContents.Length);
                requestStream.Close();

                response = (FtpWebResponse)request.GetResponse();
                response.Close();
                return(Result);
            }
            catch (System.Exception ex)
            {
                return(0);
            }
        }
Example #12
0
 private void btbReboot_Click(object sender, EventArgs e)
 {
     ssh = new SshStream(txtIP.Text, txtUsername.Text, txtPassword.Text);
     ssh.Write("reboot");
     ReadSSH();
 }