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


C# SshClient.Dispose方法代码示例

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


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

示例1: LocalVmToolStripMenuItemClick

        private void LocalVmToolStripMenuItemClick(object sender, EventArgs e)
        {
            var connectionInfo = new PasswordConnectionInfo(host, 22, username, password);
            connectionInfo.AuthenticationBanner += ConnectionInfoAuthenticationBanner;
            connectionInfo.PasswordExpired += ConnectionInfoPasswordExpired;
            sshClient = new SshClient(connectionInfo);
            sshClient.ErrorOccurred += SshClientErrorOccurred;
            Log(string.Format("Connecting to {0}:{1} as {2}", connectionInfo.Host, connectionInfo.Port, connectionInfo.Username));

            try
            {
                sshClient.Connect();
                var tunnel = sshClient.AddForwardedPort<ForwardedPortLocal>("localhost", 20080, "www.google.com", 80);
                tunnel.Start();

            }
            catch (Exception ex)
            {
                Log(ex.ToString());
            }
            finally
            {
                sshClient.Dispose();
            }
            Log("Connected");
            sshClient.ForwardedPorts.ToList().ForEach(p => Log(string.Format("SSH tunnel: {0}:{1} --> {2}:{3}", p.BoundHost, p.BoundPort, p.Host, p.Port) ));
        }
开发者ID:mrdavidlaing,项目名称:wp-appliance-commander,代码行数:27,代码来源:Main.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: 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

示例4: 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

示例5: rpi_authent

        //Authenticate users
        public bool rpi_authent(string passedUsername, string passedPassword)
        {
            SshClient AuthClient = new SshClient("rcs.rpi.edu", passedUsername, passedPassword);//Using Renci

            try
            {
                AuthClient.Connect();       //try to connect
                AuthClient.Disconnect();    //If that worked disconnect
                AuthClient.Dispose();       //Clean up connection
                username = passedUsername;  //Store data in private collection because it worked
                password = passedPassword;
                return true;
            }
            catch {
                return false;               //This failed, either server is bad, but thats public so username and password are bad
            }
        }
开发者ID:daberkow,项目名称:RPI_Helpdesk_pstat,代码行数:18,代码来源:RPI_Auth.cs

示例6: SendCommand

        /// <summary>
        /// Sends a command with or without arguments to a remote SSH server, and then returns the response. (Ensure the response will be a single line with no required input!)
        /// </summary>
        /// <param name="address">The address to connect to</param>
        /// <param name="username">The username to use to connect with</param>
        /// <param name="password">The password for the username to connect to</param>
        /// <param name="scriptName">The name of the script to run</param>
        /// <param name="arguments">The arguments (if any) to send after the scriptName</param>
        /// <returns>Either the response from the remote client (prefixed with 'P'), or the error that occurred (prefixed with 'F')</returns>
        public static string SendCommand(string address, string username, string password, string scriptName, string arguments = "")
        {
            string response = string.Empty;

            try
            {
                SshClient client = new SshClient(address, username, password);
                client.Connect();
                if (client.IsConnected)
                {
                    SshCommand command = client.CreateCommand(string.Format("{0} {1}", scriptName, arguments));
                    command.Execute();
                    response = command.Result;
                }
                client.Disconnect();
                client.Dispose();
            }
            catch (Exception exception)
            {
                return "F" + exception.Message; // F = Fail
            }

            return "P" + response; // P = Pass
        }
开发者ID:aboyce,项目名称:RasPi-Control,代码行数:33,代码来源:SSHController.cs

示例7: MikrotikExportCompact

        private string MikrotikExportCompact(string MikrotikIP, int MikrotikSSHPort, string MikrotikUser, string MikrotikPassword)
        {
            ConnectionInfo sLogin = new PasswordConnectionInfo(MikrotikIP, MikrotikSSHPort, MikrotikUser, MikrotikPassword);
            SshClient sClient = new SshClient(sLogin);
            sClient.Connect();

            SshCommand appStatCmd = sClient.CreateCommand("export compact");
            appStatCmd.Execute();

            sClient.Disconnect();
            sClient.Dispose();

            return appStatCmd.Result;
        }
开发者ID:psionika,项目名称:MikrotikSSHBackup,代码行数:14,代码来源:Form_Main.cs

示例8: Send

    // Use this for initialization
    public void Send()
    {
        string address = "10.211.55.4";
        string user = "parallels";
        string pass = "Austinv0me6fp8";
        //string cmd = "r2 '/home/parallels/Desktop/Bomb.ex_' -c 'aa;s section..text;afn main;e asm.lines=False;e asm.comments=False;e asm.calls=false;e asm.cmtflgrefs=false;e asm.cmtright=false;e asm.flags=false;e asm.function=false;e asm.functions=false;e asm.vars=false;e asm.xrefs=false;e asm.linesout=false;e asm.fcnlines=false;e asm.fcncalls=false;e asm.demangle=false;aa;s section..text;pdf>main.txt;exit' -q";
        string cmd = "r2 '/home/parallels/Desktop/Bomb.ex_' -c 'aa; s section..text; afn main; pdf @ main > main.txt' -q";
        string uploadfile = @"/Users/JonathanWatts/Desktop/Bomb.ex_";
        string uploadDirectory = "/home/parallels/Desktop/";
        //Upload a file to a linux VM
        using (var sftp = new SftpClient(address, user, pass))
        {
            try
            {
                sftp.Connect();
                using (var fileStream = new FileStream(uploadfile, FileMode.Open))
                {
                    Console.WriteLine("Uploading {0} ({1:N0} bytes)",
                                          uploadfile, fileStream.Length);
                    sftp.BufferSize = 4 * 1024; // bypass Payload error large files
                    sftp.UploadFile(fileStream, uploadDirectory + Path.GetFileName(uploadfile));
                }
                sftp.Disconnect();
                sftp.Dispose();
            }
            catch(Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }

        //This block of code will send linux terminal commands from windows machine to linux virtual machine
        using(SshClient client = new SshClient(address,user, pass))
        {
            try
            {
                Debug.Log ("Sending Command...");
                client.Connect();
                Debug.Log ("Sending Command...");
                var result = client.RunCommand(cmd);
                Debug.Log (result);
                client.Disconnect();
                Debug.Log ("Sending Command...");
                client.Dispose();
            }
            catch(Exception ex)
            {
                Debug.Log (ex.Message);
                Console.WriteLine(ex.Message);
            }
        }

        //This block of code will download the file from linux VM to the windows host machine
        try
        {
            Debug.Log ("Uploading file...");
            using (var sftp = new SftpClient(address, user, pass))
            {
                sftp.Connect();
                if(File.Exists("/Users/JonathanWatts/main333.txt"))
                {
                    File.Delete("/Users/JonathanWatts/main333.txt");
                }
                using (Stream file1 = File.OpenWrite("/Users/JonathanWatts/main333.txt"))
                {
                    try
                    {

                        sftp.DownloadFile("main.txt", file1);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                    file1.Close();

                }
                sftp.Disconnect();
                sftp.Dispose();
            }
        }
        catch(Exception ex)
        {
            Debug.Log (ex.Message);
            Console.WriteLine(ex.Message);
        }

        //SshShell shell = new SshShell(address, user, pass);
    }
开发者ID:dannisliang,项目名称:malwarevis,代码行数:90,代码来源:Send_Command.cs

示例9: Main

        static void Main(string[] args)
        {
            string address = "192.168.17.129";
            string user = "swastik";
            string pass = "singh";
            string cmd = "r2 '/home/swastik/Desktop/Bomb.ex_' -c 'aa;s section..text;pdf;pdi;e asm.lines=False;e asm.comments=False;e asm.calls=false;e asm.cmtflgrefs=fal;e asm.cmtright=false;e asm.flags=false;e asm.function=false;e asm.functions=fals;e asm.vars=false;e asm.xrefs=false;e asm.linesout=false;e asm.fcnlines=false;e asm.fcncalls=false;e asm.demangle=false;aa;s section..text;pdf>main.txt;exit' -q";
            string uploadfile = @"C:\Users\Swastik\Google Drive\Research\Malaware Visualization\Tool\radare2-w32-0.9.9-git\Bomb.ex_";
            string uploadDirectory = "/home/swastik/Desktop/";
            //Upload a file to a linux VM
            using (var sftp = new SftpClient(address, user, pass))
            {
                try
                {
                    sftp.Connect();
                    using (var fileStream = new FileStream(uploadfile, FileMode.Open))
                    {
                        Console.WriteLine("Uploading {0} ({1:N0} bytes)",
                                            uploadfile, fileStream.Length);
                        sftp.BufferSize = 4 * 1024; // bypass Payload error large files
                        sftp.UploadFile(fileStream, uploadDirectory + Path.GetFileName(uploadfile));
                    }
                    sftp.Disconnect();
                    sftp.Dispose();
                }
                catch(Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }

            //This block of code will send linux terminal commands from windows machine to linux virtual machine
            using(SshClient client = new SshClient(address,user, pass))
            {
                try
                {
                    client.Connect();
                    var result = client.RunCommand(cmd);
                    client.Disconnect();
                    client.Dispose();
                }
                catch(Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }

            //This block of code will download the file from linux VM to the windows host machine
            try
            {
                using (var sftp = new SftpClient(address, user, pass))
                {
                    sftp.Connect();
                    using (Stream file1 = File.OpenWrite("d:\\main333.txt"))
                    {
                        try
                        {

                            sftp.DownloadFile("main.txt", file1);
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.Message);
                        }
                        file1.Close();

                    }
                    sftp.Disconnect();
                    sftp.Dispose();
                }
            }
            catch(Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            //SshShell shell = new SshShell(address, user, pass);
        }
开发者ID:dannisliang,项目名称:malwarevis,代码行数:77,代码来源:Program.cs


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