コード例 #1
0
        /// <summary>Open a new session</summary>
        /// <param name="arg">The name of ID of the session to start</param>
        /// <returns>null</returns>
        internal static CommandData OpenSessionHandler(string arg)
        {
            SessionData session = SuperPuTTY.GetSessionById(arg);

            if (session != null)
            {
                SuperPuTTY.OpenSession(new SessionDataStartInfo()
                {
                    Session = session
                });
            }
            else
            {
                Log.WarnFormat("Could not start session named {0}, does it exist?", arg);
            }
            return(null);
        }
コード例 #2
0
        public SessionDataStartInfo ToSessionStartInfo()
        {
            SessionDataStartInfo ssi = null;

            if (this.SessionId != null)
            {
                // first try to resolve by sessionId
                SessionData session = SuperPuTTY.GetSessionById(this.SessionId);
                if (session == null)
                {
                    Log.WarnFormat("Session from command line not found, id={0}", this.SessionId);
                }
                else
                {
                    ssi = new SessionDataStartInfo
                    {
                        Session = session,
                        UseScp  = this.UseScp
                    };
                }
            }
            else if (this.Host != null || this.PuttySession != null)
            {
                // Host or puttySession provided
                string sessionName;
                if (this.Host != null)
                {
                    // Decode URL type host spec, if provided (e.g. ssh://localhost:2020)
                    HostConnectionString connStr = new HostConnectionString(this.Host);
                    this.Host     = connStr.Host;
                    this.Protocol = connStr.Protocol.GetValueOrDefault(this.Protocol.GetValueOrDefault(ConnectionProtocol.SSH));
                    this.Port     = connStr.Port.GetValueOrDefault(this.Port.GetValueOrDefault(dlgEditSession.GetDefaultPort(this.Protocol.GetValueOrDefault())));
                    sessionName   = this.Host;
                }
                else
                {
                    // no host provided so assume sss
                    sessionName = this.PuttySession;
                }

                ssi = new SessionDataStartInfo
                {
                    Session = new SessionData
                    {
                        Host         = this.Host,
                        SessionName  = sessionName,
                        SessionId    = SuperPuTTY.MakeUniqueSessionId(SessionData.CombineSessionIds("CLI", this.Host)),
                        Port         = this.Port.GetValueOrDefault(22),
                        Proto        = this.Protocol.GetValueOrDefault(ConnectionProtocol.SSH),
                        Username     = this.UserName,
                        Password     = this.Password,
                        PuttySession = this.PuttySession
                    },
                    UseScp = this.UseScp
                };
            }

            if (ssi == null)
            {
                Log.WarnFormat("Could not determine session or host to connect.  SessionId or Host or PuttySession must be provided");
            }

            return(ssi);
        }