예제 #1
0
        private static void SendMyVersion(AbstractSocket stream, SSHConnectionParameter param)
        {
            string cv = SSHUtil.ClientVersionString(param.Protocol);

            if (param.Protocol == SSHProtocol.SSH1)
            {
                cv += param.SSH1VersionEOL;
            }
            else
            {
                cv += "\r\n";
            }
            byte[] data = Encoding.ASCII.GetBytes(cv);
            stream.Write(data, 0, data.Length);
        }
예제 #2
0
        internal static SSHConnection Connect(SSHConnectionParameter param, ISSHConnectionEventReceiver receiver, ProtocolNegotiationHandler pnh, AbstractSocket s)
        {
            if (param.UserName == null)
            {
                throw new InvalidOperationException("UserName property is not set");
            }
            if (param.Password == null)
            {
                throw new InvalidOperationException("Password property is not set");
            }

            return(ConnectMain(param, receiver, pnh, s));
        }
예제 #3
0
        private static SSHConnection ConnectMain(SSHConnectionParameter param, ISSHConnectionEventReceiver receiver, ProtocolNegotiationHandler pnh, AbstractSocket s)
        {
            pnh.Wait();

            if (pnh.State != ReceiverState.Ready)
            {
                throw new SSHException(pnh.ErrorMessage);
            }

            string sv = pnh.ServerVersion;

            SSHConnection con = null;

            if (param.Protocol == SSHProtocol.SSH1)
            {
                con = new SSH1Connection(param, receiver, sv, SSHUtil.ClientVersionString(param.Protocol));
            }
            else
            {
                con = new SSH2Connection(param, receiver, sv, SSHUtil.ClientVersionString(param.Protocol));
            }

            s.SetHandler(con.PacketBuilder);
            SendMyVersion(s, param);

            if (con.Connect(s) != AuthenticationResult.Failure)
            {
                return(con);
            }
            else
            {
                s.Close();
                return(null);
            }
        }
예제 #4
0
 internal abstract AuthenticationResult Connect(AbstractSocket target);