public void close() { if (_session != null) { _session.InternalTerminate(); } if (_connector != null) { if (typeof(SSHConnector) == _connector.GetType()) { ((SSHConnector)_connector).Result.Close(); } else { ((TelnetConnector)_connector).Result.Close(); } } if (tcp != null) { tcp = null; } if (ssh != null) { ssh = null; } if (_param != null) { _param = null; } _connector = null; _session = null; _isConnected = false; _timedOut = false; }
public ITerminalParameter PrepareTerminalParameter(string UserName, string Pwd, string DestHost, int Port, ConnectionMethod m, string PublicKeyFile, LogType logType, string logPath) { string msg = null; if (_terminalOptions == null) { _terminalOptions = new TerminalOptions(""); } if (_terminalSettings == null) { _terminalSettings = new TerminalSettings(); } try { if (Port == 0) { if (m == ConnectionMethod.Telnet) { Port = 23; } else { Port = 22; } } tcp = _Console.CreateDefaultTelnetParameter(); tcp.Destination = DestHost; tcp.Port = Port; if (m == ConnectionMethod.SSH1 || (m == ConnectionMethod.SSH2)) { SSHLoginParameter sp = _Console.CreateDefaultSSHParameter(); ssh = sp; ssh.Destination = DestHost; ssh.Port = Port; ssh.Method = m == ConnectionMethod.SSH1 ? SSHProtocol.SSH1 : SSHProtocol.SSH2; ssh.Account = UserName; ssh.PasswordOrPassphrase = Pwd; } if (DestHost.Length == 0) { msg = "Message.TelnetSSHLogin.HostIsEmpty"; } //ƒƒOÝ’è ISimpleLogSettings logsettings = null; if (logType != LogType.None) { if (logPath.Length == 0) { logPath = AppDomain.CurrentDomain.BaseDirectory;// +DestHost; } logsettings = new SimpleLogSettings(); logsettings.LogPath = logPath; logsettings.LogType = logType; LogFileCheckResult r = LogUtil.CheckLogFileName(logPath); if (r == LogFileCheckResult.Cancel || r == LogFileCheckResult.Error) { return(null); } logsettings.LogAppend = (r == LogFileCheckResult.Append); if (logsettings == null) { return(null); //“®ìƒLƒƒƒ“ƒZƒ‹ } _terminalOptions.DefaultLogType = logType; _terminalOptions.DefaultLogDirectory = logPath; } _param = (ITerminalParameter)tcp; //(ITerminalParameter)tcp.GetAdapter(typeof(ITerminalParameter)); TerminalType terminal_type = TerminalType.VT100; _param.SetTerminalName(ToTerminalName(terminal_type)); if (ssh != null) { Debug.Assert(ssh != null); if (PublicKeyFile.Length > 0) { ssh.AuthenticationType = AuthenticationType.PublicKey; if (!File.Exists(PublicKeyFile)) { msg = "Message.TelnetSSHLogin.KeyFileNotExist"; } else { ssh.IdentityFileName = PublicKeyFile; } } } ITerminalSettings settings = this.TerminalSettings; settings.BeginUpdate(); settings.Caption = DestHost; //settings.Icon = IconList.LoadIcon(IconList.ICON_NEWCONNECTION); settings.Encoding = EncodingType.ISO8859_1; settings.LocalEcho = false; settings.TransmitNL = NewLine.CRLF; // .LF; //.CR; settings.LineFeedRule = ConnectionParam.LineFeedRule.Normal; settings.TerminalType = terminal_type; settings.DebugFlag = _debug; if (logsettings != null) { settings.LogSettings.Reset(logsettings); } settings.EndUpdate(); if (msg != null) { if (_debug > 0) //ShowError(msg); { Console.WriteLine(msg); } return(null); } else { return((ITerminalParameter)tcp); //.GetAdapter(typeof(ITerminalParameter)); } } catch (Exception ex) { if (_debug > 0) { Console.WriteLine(ex.Message); } return(null); } }