Esempio n. 1
0
        public static void testc()
        {
            Chilkat.SshTunnel sshTunnel = new Chilkat.SshTunnel();

            bool success;

            success = sshTunnel.UnlockComponent("30-day trial");
            if (success != true)
            {
                //textBox1.Text += sshTunnel.LastErrorText + "\r\n";
                Console.WriteLine("fail trial");
                return;
            }

//  The destination host/port is the database server.
//  The DestHostname may be the domain name or
//  IP address (in dotted decimal notation) of the database
//  server.
            sshTunnel.DestPort     = 3306;
            sshTunnel.DestHostname = "219.245.64.4";

//  Provide information about the location of the SSH server,
//  and the authentication to be used with it. This is the
//  login information for the SSH server (not the database server).
            sshTunnel.SshHostname = "219.245.64.4";
            sshTunnel.SshPort     = 22;
            sshTunnel.SshLogin    = "******";
            sshTunnel.SshPassword = "******";

//  Start accepting connections in a background thread.
//  The SSH tunnels are autonomously run in a background
//  thread.  There is one background thread for accepting
//  connections, and another for managing the tunnel pool.
            int listenPort;

            listenPort = 9999;
            success    = sshTunnel.BeginAccepting(listenPort);
            if (success != true)
            {
                Console.WriteLine(sshTunnel.LastErrorText);
                return;
            }
        }
Esempio n. 2
0
        public void Open()
        {
            try
            {
                if (session != null && IsOpen())
                {
                    return;
                }

                bool success;

                session = new Chilkat.SshTunnel();

                success = session.UnlockComponent("ITAYHESSH_d674QVQunRnj");
                if (success != true)
                {
                    throw new DuradosException(session.LastErrorText);
                }

                //  The destination host/port is the database server.
                //  The DestHostname may be the domain name or
                //  IP address (in dotted decimal notation) of the database
                //  server.
                session.DestPort     = remotePort;
                session.DestHostname = "localhost";

                //  Provide information about the location of the SSH server,
                //  and the authentication to be used with it. This is the
                //  login information for the SSH server (not the database server).
                session.SshHostname = tunnel.RemoteHost;
                session.SshPort     = tunnel.Port;
                session.SshLogin    = tunnel.User;
                if (string.IsNullOrEmpty(tunnel.Password))
                {
                    Chilkat.SshKey sshKey = new Chilkat.SshKey();
                    //string sss = sshKey.LoadText(@"G:\Dev\Relly - new\Duradus.Web.Mvc.App\Modubiz2012.pem");
                    string keyText = tunnel.PrivateKey;
                    success = sshKey.FromOpenSshPrivateKey(keyText);
                    //string fff = sshKey.ToOpenSshPrivateKey(false);
                    success = session.SetSshAuthenticationKey(sshKey);
                    if (success)
                    {
                    }
                }
                else
                {
                    session.SshPassword = tunnel.Password;
                }

                //  Start accepting connections in a background thread.
                //  The SSH tunnels are autonomously run in a background
                //  thread.  There is one background thread for accepting
                //  connections, and another for managing the tunnel pool.
                int listenPort;
                listenPort = localPort;
                success    = session.BeginAccepting(listenPort);
                if (success != true)
                {
                    throw new DuradosException(session.LastErrorText);
                }

                //  At this point you may connect to the database server through
                //  the SSH tunnel.  Your database connection string would
                //  use "localhost" for the hostname and 3316 for the port.
                //  We're not going to show the database coding here,
                //  because it can vary depending on the API you're using
                //  (ADO, ODBC, OLE DB, etc. )
            }
            catch (Exception exception)
            {
                throw new DuradosException("Could not  open SSH tunnel", exception);
            }
        }