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


C# SshClient.Disconnect方法代码示例

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


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

示例1: Test_Connect_Handle_HostKeyReceived

        public void Test_Connect_Handle_HostKeyReceived()
        {
            var host = Resources.HOST;
            var username = Resources.USERNAME;
            var password = Resources.PASSWORD;
            var hostKeyValidated = false;

            #region Example SshClient Connect HostKeyReceived
            using (var client = new SshClient(host, username, password))
            {
                client.HostKeyReceived += delegate(object sender, HostKeyEventArgs e)
                {
                    hostKeyValidated = true;

                    if (e.FingerPrint.SequenceEqual(new byte[] { 0x00, 0x01, 0x02, 0x03 }))
                    {
                        e.CanTrust = true;
                    }
                    else
                    {
                        e.CanTrust = false;
                    }
                };
                client.Connect();
                //  Do something here
                client.Disconnect();
            }
            #endregion

            Assert.IsTrue(hostKeyValidated);
        }
开发者ID:delfinof,项目名称:ssh.net,代码行数:31,代码来源:SshClientTest.cs

示例2: Test_KeyExchange_Rekeying

        public void Test_KeyExchange_Rekeying()
        {
            var connectionInfo = new PasswordConnectionInfo(Resources.HOST, 22, Resources.USERNAME, Resources.PASSWORD);

            using (var client = new SshClient(connectionInfo))
            {
                client.Connect();
                //  TODO:   Add test to test re-keying
                Assert.Inconclusive();
                client.Disconnect();
            }
        }
开发者ID:nahidupa,项目名称:localtunnel-net-client,代码行数:12,代码来源:TestKeyExchange.cs

示例3: Main

    static void Main(string[] args)
    {
        // Setup Credentials and Server Information
        ConnectionInfo ConnNfo = new ConnectionInfo("10.141.3.110",22,"root",
            new AuthenticationMethod[]{

                // Pasword based Authentication
                new PasswordAuthenticationMethod("root","ismail"),

            }
        );

        // Execute (SHELL) Commands
        using (var sshclient = new SshClient(ConnNfo)){
            sshclient.Connect();

            // quick way to use ist, but not best practice - SshCommand is not Disposed, ExitStatus not checked...
            Console.WriteLine("telnet localhost 6571");
            Console.WriteLine("denemeeeeeee");
            //Console.WriteLine(sshclient.CreateCommand("cd /tmp && ls -lah").Execute());
            //Console.WriteLine(sshclient.CreateCommand("pwd").Execute());
            //Console.WriteLine(sshclient.CreateCommand("cd /tmp/uploadtest && ls -lah").Execute());
            sshclient.Disconnect();
        }
        Console.ReadKey();
    }
开发者ID:isotbiberi,项目名称:ATA50DOME,代码行数:26,代码来源:Program.cs

示例4: Test_Execute_Command_Asynchronously_With_Callback

        public void Test_Execute_Command_Asynchronously_With_Callback()
        {
            using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
            {
                client.Connect();

                var callbackCalled = false;

                var cmd = client.CreateCommand("sleep 5s; echo 'test'");
                var asyncResult = cmd.BeginExecute(new AsyncCallback((s) =>
                {
                    callbackCalled = true;
                }), null);
                while (!asyncResult.IsCompleted)
                {
                    Thread.Sleep(100);
                }

                cmd.EndExecute(asyncResult);

                Assert.IsTrue(callbackCalled);

                client.Disconnect();
            }
        }
开发者ID:nahidupa,项目名称:localtunnel-net-client,代码行数:25,代码来源:TestSshCommand.cs

示例5: BeginExecuteTest

        public void BeginExecuteTest()
        {
            string expected = "123\n";
            string result;

            using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
            {
                #region Example SshCommand CreateCommand BeginExecute IsCompleted EndExecute

                client.Connect();

                var cmd = client.CreateCommand("sleep 15s;echo 123"); // Perform long running task

                var asynch = cmd.BeginExecute();

                while (!asynch.IsCompleted)
                {
                    //  Waiting for command to complete...
                    Thread.Sleep(2000);
                }
                result = cmd.EndExecute(asynch);
                client.Disconnect();

                #endregion

                Assert.IsNotNull(asynch);
                Assert.AreEqual(expected, result);
            }
        }
开发者ID:pecegit,项目名称:sshnet,代码行数:29,代码来源:SshCommandTest.cs

示例6: CleanCurrentFolder

 public void CleanCurrentFolder()
 {
     using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
     {
         client.Connect();
         client.RunCommand("rm -rf *");
         client.Disconnect();
     }
 }
开发者ID:nahidupa,项目名称:localtunnel-net-client,代码行数:9,代码来源:CreateDirectoryTest.cs

示例7: Test_AddForwardedPort_Local_Hosts_Are_Empty

 public void Test_AddForwardedPort_Local_Hosts_Are_Empty()
 {
     using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
     {
         client.Connect();
         var port1 = client.AddForwardedPort<ForwardedPortLocal>(string.Empty, 8080, string.Empty, 80);
         client.Disconnect();
     }
 }
开发者ID:nahidupa,项目名称:localtunnel-net-client,代码行数:9,代码来源:TestPortForwarding.cs

示例8: Test_AddForwardedPort_Remote_Hosts_Are_Null

 public void Test_AddForwardedPort_Remote_Hosts_Are_Null()
 {
     using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
     {
         client.Connect();
         var port1 = client.AddForwardedPort<ForwardedPortRemote>(null, 8080, null, 80);
         client.Disconnect();
     }
 }
开发者ID:nahidupa,项目名称:localtunnel-net-client,代码行数:9,代码来源:TestPortForwarding.cs

示例9: Test_AddForwardedPort_Invalid_PortNumber

 public void Test_AddForwardedPort_Invalid_PortNumber()
 {
     using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
     {
         client.Connect();
         var port1 = client.AddForwardedPort<ForwardedPortRemote>("localhost", IPEndPoint.MaxPort+1, "www.renci.org", IPEndPoint.MaxPort+1);
         client.Disconnect();
     }
 }
开发者ID:nahidupa,项目名称:localtunnel-net-client,代码行数:9,代码来源:TestPortForwarding.cs

示例10: Test_EndExecute_Before_BeginExecute

 public void Test_EndExecute_Before_BeginExecute()
 {
     using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
     {
         client.Connect();
         var cmd = client.CreateCommand("ls -l");
         cmd.EndExecute(null);
         client.Disconnect();
     }
 }
开发者ID:nahidupa,项目名称:localtunnel-net-client,代码行数:10,代码来源:TestSshCommand.cs

示例11: Test_Cipher_Cast128CBC_Connection

        public void Test_Cipher_Cast128CBC_Connection()
        {
            var connectionInfo = new PasswordConnectionInfo(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD);
            connectionInfo.Encryptions.Clear();
            connectionInfo.Encryptions.Add("cast128-cbc", new CipherInfo(128, (key, iv) => { return new CastCipher(key, new CbcCipherMode(iv), null); }));

            using (var client = new SshClient(connectionInfo))
            {
                client.Connect();
                client.Disconnect();
            }
        }
开发者ID:sshnet,项目名称:SSH.NET,代码行数:12,代码来源:CastCipherTest.cs

示例12: Test_HostKey_SshDss_Connection

        public void Test_HostKey_SshDss_Connection()
        {
            var connectionInfo = new PasswordConnectionInfo(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD);
            connectionInfo.HostKeyAlgorithms.Clear();
            connectionInfo.HostKeyAlgorithms.Add("ssh-dss", (data) => { return new KeyHostAlgorithm("ssh-dss", new DsaKey(), data); });

            using (var client = new SshClient(connectionInfo))
            {
                client.Connect();
                client.Disconnect();
            }
        }
开发者ID:delfinof,项目名称:ssh.net,代码行数:12,代码来源:KeyHostAlgorithmTest.cs

示例13: Test_HMac_Sha256_Connection

        public void Test_HMac_Sha256_Connection()
        {
            var connectionInfo = new PasswordConnectionInfo(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD);
            connectionInfo.HmacAlgorithms.Clear();
            connectionInfo.HmacAlgorithms.Add("hmac-sha2-256", new HashInfo(32 * 8, CryptoAbstraction.CreateHMACSHA256));

            using (var client = new SshClient(connectionInfo))
            {
                client.Connect();
                client.Disconnect();
            }
        }
开发者ID:sshnet,项目名称:SSH.NET,代码行数:12,代码来源:HMacTest.cs

示例14: Test_Cipher_Aes256CBC_Connection

        public void Test_Cipher_Aes256CBC_Connection()
        {
            var connectionInfo = new PasswordConnectionInfo(Resources.HOST, 22, Resources.USERNAME, Resources.PASSWORD);
            connectionInfo.Encryptions.Clear();
            connectionInfo.Encryptions.Add("aes256-cbc", new CipherInfo(256, (key, iv) => { return new AesCipher(key, new CbcCipherMode(iv), null); }));

            using (var client = new SshClient(connectionInfo))
            {
                client.Connect();
                client.Disconnect();
            }
        }
开发者ID:nahidupa,项目名称:localtunnel-net-client,代码行数:12,代码来源:TestCipher.cs

示例15: Test_HMac_Sha1_Connection

        public void Test_HMac_Sha1_Connection()
        {
            var connectionInfo = new PasswordConnectionInfo(Resources.HOST, 22, Resources.USERNAME, Resources.PASSWORD);
            connectionInfo.HmacAlgorithms.Clear();
            connectionInfo.HmacAlgorithms.Add("hmac-sha1", (key) => { return new HMac<SHA1Hash>(key.Take(20).ToArray()); });

            using (var client = new SshClient(connectionInfo))
            {
                client.Connect();
                client.Disconnect();
            }
        }
开发者ID:nahidupa,项目名称:localtunnel-net-client,代码行数:12,代码来源:TestHMac.cs


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