Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using Renci.SshNet;
- namespace simplest_ssh_shell_bare_text
- {
- public partial class Form1 : Form
- {
- /* Reserving Global Objects */
- SshClient SSHServerConnection;
- ShellStream SSHStream;
- /* Creating Global variables for the Global Objects */
- private string sIP, sUSERNAME, sPASSWORD;
- private int iIPORT;
- private void buttonDISCONNECT_Click(object sender, EventArgs e)
- {
- try
- {
- /* Calling Disconnect Method from SshClient namespace */
- SSHServerConnection.Disconnect();
- MessageBox.Show("Disconnect from the Server sucessful");
- }
- catch
- {
- MessageBox.Show("COULD NOT DETERMISH THE CONNECTION");
- }
- }
- public Form1()
- {
- InitializeComponent();
- }
- private void groupBox1_Enter(object sender, EventArgs e)
- {
- }
- private void buttonCONNECT_Click(object sender, EventArgs e)
- {
- try
- {
- /* Collection connection data from the Textboxes */
- sIP = textBoxIP.Text;
- iIPORT = Convert.ToInt32(textBoxPORT.Text);
- sUSERNAME = textBoxUSER.Text;
- sPASSWORD = textBoxPASSWORD.Text;
- /* FILL THE GLOBAL OBJECT WITH DATA */
- SSHServerConnection = new SshClient(sIP, iIPORT, sUSERNAME, sPASSWORD);
- /* LET THE OBJECT USE HIS CONNECT METHOD object.method */
- SSHServerConnection.Connect();
- /* FILL THE GLOBAL STREAM OBJECT WHICH LAYS UNDER THE THE SSHCLIENT OBJECT, WITH DATA */
- SSHStream = SSHServerConnection.CreateShellStream("Streamy", 80, 24, 800, 600, 1024);
- MessageBox.Show("Server connection etablished");
- }
- catch
- {
- MessageBox.Show("COULD NOT CONNECT TO THE SERVER");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement