コード例 #1
0
        // Konstruktor zur Verbindungseinstellung mittels Zertifikat
        public SSH(string ipadress, string port, string username, string certificate, string passphrase)
        {
            // Variablen überprüfen
            if (ipadress == ResourceText.EMPTY)
            {
                throw new Exception(Handler.CreateException(ResourceText.Message, ResourceText.ExceptionClass, ResourceText.ExceptionSSH, ResourceText.ExceptionIP));
            }
            if (username == ResourceText.EMPTY)
            {
                throw new Exception(Handler.CreateException(ResourceText.Message, ResourceText.ExceptionClass, ResourceText.ExceptionSSH, ResourceText.ExceptionUser));
            }
            if (Tool.String2Int(port, 22) > _maxport)
            {
                throw new Exception(Handler.CreateException(ResourceText.Message, ResourceText.ExceptionClass, ResourceText.ExceptionSSH, ResourceText.ExceptionPort));
            }
            if (certificate == ResourceText.EMPTY)
            {
                throw new Exception(Handler.CreateException(ResourceText.Message, ResourceText.ExceptionClass, ResourceText.ExceptionSSH, ResourceText.ExceptionCertificate));
            }

            // Klassenvariablen beschreiben
            _ipaddress   = ipadress;
            _port        = port;
            _username    = username;
            _certificate = certificate;
            _passphrase  = Chiper.Decrypt(passphrase, ResourceText.Passphrase);

            // Zertifikat basierte Verbindung erstellen
            _connection = new ConnectionInfo(ipadress, Tool.String2Int(port, 22), username, new PrivateKeyAuthenticationMethod(username, new PrivateKeyFile[] { new PrivateKeyFile(@certificate, passphrase) }));
        }
コード例 #2
0
        // Konstruktor zur Verbindungseinstellung mittels Benutzer und Passwort
        public SSH(string ipaddress, string port, string username, string password = null)
        {
            // Eingabevariablen überprüfen
            if (ipaddress == ResourceText.EMPTY || ipaddress.Length > Convert.ToInt16(ResourceText.sshIPAddressLength))
            {
                throw new Exception(Handler.CreateException(ResourceText.Message, ResourceText.ExceptionClass, ResourceText.ExceptionSSH, ResourceText.ExceptionIP));
            }
            if (username == ResourceText.EMPTY || username.Length > Convert.ToInt16(ResourceText.sshFieldMaxLength))
            {
                throw new Exception(Handler.CreateException(ResourceText.Message, ResourceText.ExceptionClass, ResourceText.ExceptionSSH, ResourceText.ExceptionUser));
            }
            if (Tool.String2Int(port, Convert.ToInt16(ResourceText.sshPORT)) > _maxport || Tool.String2Int(port, Convert.ToInt16(ResourceText.sshPORT)) < _minport)
            {
                throw new Exception(Handler.CreateException(ResourceText.Message, ResourceText.ExceptionClass, ResourceText.ExceptionSSH, ResourceText.ExceptionPort));
            }

            // Klassenvariablen mit übergebenen Werten an Konstruktor beschreiben
            _ipaddress = ipaddress;
            _username  = username;
            _port      = port;

            try
            {
                // Versuchen übergebenes Passwort zu entschlüsseln
                _password = Chiper.Decrypt(password, ResourceText.Passphrase);
            }
            catch
            {
                throw new Exception(Handler.CreateException(ResourceText.Message, ResourceText.ExceptionClass, ResourceText.ExceptionSSH, ResourceText.ExceptionPasswortDecrypt));
            }

            // Passwort basierte Verbindung erstellen
            _connection = new ConnectionInfo(ipaddress, Tool.String2Int(port, 22), username, new AuthenticationMethod[] { new PasswordAuthenticationMethod(username, password) });
        }