Beispiel #1
0
        private void PASS(FtpCommand ftpCmd)
        {
            if (string.IsNullOrEmpty(UserName))
            {
                throw new NeedUserInfoException();
            }
            else
            {
                if (ftpCmd.Parameters.Count == 0)
                {
                    throw new SyntaxException();
                }

                Password = ftpCmd.Parameters[0];
                if (ftpServer.ValidateUser(this))
                {
                    if (user.ConnCount + 1 > user.MaxConnectionCount)
                    {
                        Response("421 Too many users logged in for this account.");

                        this.user = null;
                    }
                    else
                    {
                        Statue = FtpSessionStatue.Wait;
                        user.ConnCount++;
                        Response("230 User successfully logged in.");
                    }
                }
                else
                {
                    throw new LoginFailException();
                }
            }
        }
Beispiel #2
0
        public FtpServer()
        {
            EnableCheckHeartBeat = true;

            //1分钟内客户端没有反应,就踢出客户端
            HeartBeatPeriod = 60000;

            //默认FTP监听端口
            Port = 12001;

            //FTP协议使用的命令分隔符号
            NewLines = new string[] { "\r\n" };

            WelcomeMessage = "220 Midapex Village FTP Server V2.1 ready.";
            ByeMessage     = "Bye.";

            //默认使用中文字符集合来操作,如果是其他的语言,请重新指定。
            Encoding = Encoding.GetEncoding("utf-8");

            //默认允许匿名登陆
            AllowAnonymous = true;

            //默认设置匿名用户的信息
            anonymousUser = new FtpUser("anonymous");
        }
Beispiel #3
0
        /// <summary>
        /// 是否是一个合法的用户
        /// </summary>
        /// <param name="session"></param>
        /// <returns></returns>
        protected internal virtual bool ValidateUser(FtpSession session)
        {
            if (AllowAnonymous && session.UserName == AnonymousUser.UserName)
            {
                session.user = AnonymousUser;
                return(true);
            }

            try
            {
                FtpUser user = Users[session.UserName];
                if (user.Password == session.Password)
                {
                    session.user = user;

                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (KeyNotFoundException)
            {
                return(false);
            }
        }
Beispiel #4
0
 /// <summary>
 /// 删除一个用户
 /// </summary>
 /// <param name="user"></param>
 public void RemoveUser(FtpUser user)
 {
     Users.Remove(user.UserName);
 }
Beispiel #5
0
 /// <summary>
 /// 添加一个用户
 /// </summary>
 /// <param name="user"></param>
 public void AddUser(FtpUser user)
 {
     Users.Add(user.UserName, user);
 }