public static SocketWithTimeout StartNewConnection(ISocketWithTimeoutClient client, ChannelProfile prof, string password, HostKeyCheckCallback keycheck) { SocketWithTimeout swt; swt = new SSHConnector(prof, password, keycheck); if(Env.Options.UseSocks) swt.AsyncConnect(client, CreateSocksParam(prof.SSHHost, prof.SSHPort)); else swt.AsyncConnect(client, prof.SSHHost, prof.SSHPort); return swt; }
public void Connect() { // 先判断连接状态 if (IsConnected || _isConnecting) { return; } _isConnecting = true; if (statusText == null) { statusText = new Label(); statusText.Dock = DockStyle.Fill; statusText.BackColor = Color.White; statusText.ForeColor = Color.Black; statusText.Font = new Font("Microsoft YaHei", 10); statusText.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; } statusText.Text = "正在连接"; statusText.Visible = true; this.Invalidate(); this.Controls.Add(statusText); if (GApp._frame == null) { GApp.Run(new string[0]); GApp.Options.BGColor = this.BackColor; GApp.Options.TextColor = this.ForeColor; GApp.Options.RightButtonAction = RightButtonAction.Paste; GApp.Options.AutoCopyByLeftButton = true; //GApp.Options.WarningOption = WarningOption.Ignore; GApp.Options.Font = this.Font; GApp._frame._multiPaneControl.InitUI(null, GApp.Options); GEnv.InterThreadUIService.MainFrameHandle = GApp._frame.Handle; } try { //------------------------------------------------------------------------ SSHTerminalParam sshp = new SSHTerminalParam(Poderosa.ConnectionParam.ConnectionMethod.SSH2, this.Host, this.UserName, this.Password); sshp.AuthType = AuthType.Password; sshp.IdentityFile = string.Empty; sshp.Encoding = EncodingType.UTF8; sshp.Port = this._port; sshp.RenderProfile = new RenderProfile(); sshp.TerminalType = TerminalType.XTerm; CommunicationUtil.SilentClient s = new CommunicationUtil.SilentClient(); Size sz = this.Size; SocketWithTimeout swt = new SSHConnector(sshp, sz, sshp.Passphrase, null); swt.AsyncConnect(s, sshp.Host, sshp.Port, (ct, errorMessage) => { if (ct == null) { statusText.Invoke(new Action(() => { statusText.Text = "连接异常:" + errorMessage; })); return; } if (this._terminalPane == null) { this.Invoke(new Action(() => { this._terminalPane = new TerminalPane(); InitTerminalPane(ct); })); } else { this._terminalPane.Invoke(new Action(() => { this._terminalPane.Detach(); InitTerminalPane(ct); })); } }); } catch (Exception ex) { statusText.Text = "连接异常:" + ex.Message; return; } _isConnecting = false; }
public void Connect() { #region old stuff /* * Poderosa.ConnectionParam.LogType logType = Poderosa.ConnectionParam.LogType.Default; * string file = null; * if (this.TerminalPane.Connection != null) * { * logType = this.TerminalPane.Connection.LogType; * file = this.TerminalPane.Connection.LogPath; * //GApp.GetConnectionCommandTarget().Close(); * this.TerminalPane.Connection.Close(); * this.TerminalPane.Detach(); * } * * * SSHTerminalParam p = new SSHTerminalParam((Poderosa.ConnectionParam.ConnectionMethod)this.Method, this.Host, this.UserName, this.Password); * * GApp.GlobalCommandTarget.SilentNewConnection(p); * * * if (file != null) * this.SetLog((LogType) logType, file, true); */ #endregion // Save old log info in case this is a reconnect Poderosa.ConnectionParam.LogType logType = Poderosa.ConnectionParam.LogType.Default; string file = null; if (this.TerminalPane.Connection != null) { logType = this.TerminalPane.Connection.LogType; file = this.TerminalPane.Connection.LogPath; //GApp.GetConnectionCommandTarget().Close(); this.TerminalPane.Connection.Close(); this.TerminalPane.Detach(); } try { //------------------------------------------------------------------------ SSHTerminalParam sshp = new SSHTerminalParam((Poderosa.ConnectionParam.ConnectionMethod) this.Method, this.Host, this.UserName, this.Password); sshp.AuthType = this.AuthType; sshp.IdentityFile = this.IdentifyFile; sshp.Encoding = EncodingType.ISO8859_1; sshp.Port = 22; sshp.RenderProfile = new RenderProfile(); sshp.TerminalType = TerminalType.XTerm; CommunicationUtil.SilentClient s = new CommunicationUtil.SilentClient(); Size sz = this.Size; SocketWithTimeout swt; swt = new SSHConnector((Poderosa.ConnectionParam.SSHTerminalParam)sshp, sz, sshp.Passphrase, (HostKeyCheckCallback)null); swt.AsyncConnect(s, sshp.Host, sshp.Port); ConnectionTag ct = s.Wait(swt); this.TerminalPane.FakeVisible = true; this.TerminalPane.Attach(ct); ct.Receiver.Listen(); //------------------------------------------------------------- if (file != null) { this.SetLog((LogType)logType, file, true); } this.TerminalPane.ConnectionTag.RenderProfile = new RenderProfile(); this.SetPaneColors(Color.LightBlue, Color.Black); } catch { //MessageBox.Show(e.Message, "Connection Error"); return; } }