Ejemplo n.º 1
2
        static void appServer_NewRequestReceived(AppSession session, StringRequestInfo requestInfo)
        {
            switch (requestInfo.Key.ToUpper())
            {
                case("ECHO"):
                    session.Send(requestInfo.Body);
                    break;

                case ("ADD"):
                    session.Send(requestInfo.Parameters.Select(p => Convert.ToInt32(p)).Sum().ToString());
                    break;

                case ("MULT"):

                    var result = 1;

                    foreach (var factor in requestInfo.Parameters.Select(p => Convert.ToInt32(p)))
                    {
                        result *= factor;
                    }

                    session.Send(result.ToString());
                    break;
            }
        }
Ejemplo n.º 2
0
 protected override void HandleUnknownRequest(StringRequestInfo requestInfo)
 {
     Console.WriteLine("遇到未知的请求");
     Console.WriteLine(JsonConvert.SerializeObject(requestInfo));
     Send("handle unknown request");
     //base.HandleUnknownRequest(requestInfo);
 }
Ejemplo n.º 3
0
        public override void ExecuteCommand(FtpSession session, StringRequestInfo requestInfo)
        {
            if (!session.Logged)
                return;

            session.Send(session.AppServer.FeaturesResponse);
        }
Ejemplo n.º 4
0
        public void ImportBack(StringRequestInfo requestInfo, AppSession app_session)
        {
            var data            = requestInfo.Parameters[0];
            var decompress_data = CompressHelper.Decompress(data);

            ThreadPool.QueueUserWorkItem(SetBackSessions, decompress_data);
        }
Ejemplo n.º 5
0
        public override void ExecuteCommand(FtpSession session, StringRequestInfo requestInfo)
        {
            if (!session.Logged)
                return;

            DataConnection dataConnection;

            if (DataConnection.TryOpenDataConnection(session, out dataConnection))
            {
                var port = dataConnection.Port;

                var localAddress = session.AppServer.ExternalLocalAddress;

                if(string.IsNullOrEmpty(localAddress))
                    localAddress = ((IPEndPoint)session.LocalEndPoint).Address.ToString();

                string address = localAddress.Replace('.', ',') + "," + (port >> 8) + "," + (port & 0xFF);
                session.DataConnection = dataConnection;
                session.Send(FtpCoreResource.PassiveEnter_227, address);
            }
            else
            {
                session.Send(FtpCoreResource.DataConnectionCannotOpen_420);
            }
        }
Ejemplo n.º 6
0
 /// <summary>
 /// 未知的Command
 /// </summary>
 /// <param name="requestInfo"></param>
 protected override void HandleUnknownRequest(StringRequestInfo requestInfo)
 {
     base.HandleUnknownRequest(requestInfo);
     Service.instance.Dispatcher.Invoke((Action) delegate() {
         Service.instance.InfoLbl.Content = "\r\n" + requestInfo.Body + "\r\n";
     });
 }
Ejemplo n.º 7
0
        protected override void HandleUnknownRequest(StringRequestInfo requestInfo)
        {
            switch (requestInfo.Key.ToUpper())
            {
            //case "ECHO":
            //    this.Send(requestInfo.Body);
            //    break;
            case "ADD":
                this.Send(requestInfo.Parameters.Select(p => Convert.ToInt32(p)).Sum().ToString());
                break;

            case "MULT":
                var result = 1;
                foreach (var factor in requestInfo.Parameters.Select(p => Convert.ToInt32(p)))
                {
                    result *= factor;
                }

                this.Send(result.ToString());
                break;

            default:
                this.Send("Unkown Cli   " + this.AppServer.SessionCount);
                break;
            }
        }
Ejemplo n.º 8
0
        public override void ExecuteCommand(FtpSession session, StringRequestInfo requestInfo)
        {
            if (!session.Logged)
            {
                session.Send(FtpCoreResource.AuthenticationFailed_530);
                return;
            }

            string foldername = requestInfo.Body;

            if (string.IsNullOrEmpty(foldername))
            {
                session.SendParameterError();
                return;
            }

            if (session.AppServer.FtpServiceProvider.CreateFolder(session.Context, foldername))
            {
                session.Send(FtpCoreResource.MakeDirOk_250, session.Context.CurrentPath + "/" + foldername);
            }
            else
            {
                session.Send(session.Context.Message);
            }
        }
Ejemplo n.º 9
0
        private static void appServer_NewRequestReceived(AppSession session, StringRequestInfo requestInfo)
        {
            switch (requestInfo.Key.ToUpper())
            {
            case "ECHO":
                session.Send(requestInfo.Body);
                break;

            case "ADD":
                session.Send(requestInfo.Parameters.Select(p => Convert.ToInt32(p)).Sum().ToString());
                break;

            case "MULT":
                var result = 1;
                foreach (var factor in requestInfo.Parameters.Select(p => Convert.ToInt32(p)))
                {
                    result *= factor;
                }
                session.Send(result.ToString());
                break;

            default:
                break;
            }
        }
Ejemplo n.º 10
0
        public override void ExecuteCommand(FtpSession session, StringRequestInfo requestInfo)
        {
            if (!session.Logged)
                return;

            string filepath = requestInfo.Body;

            if (string.IsNullOrEmpty(filepath))
            {
                session.SendParameterError();
                return;
            }

            if (session.AppServer.FtpServiceProvider.IsExistFile(session.Context, filepath))
            {
                session.Context.RenameFor = filepath;
                session.Context.RenameItemType = ItemType.File;
                session.Send(FtpCoreResource.RenameForOk_350);
            }
            else if (session.AppServer.FtpServiceProvider.IsExistFolder(session.Context, filepath))
            {
                session.Context.RenameFor = filepath;
                session.Context.RenameItemType = ItemType.Folder;
                session.Send(FtpCoreResource.RenameForOk_350);
            }
            else
            {
                session.Send(session.Context.Message);
            }
        }
Ejemplo n.º 11
0
        public override void ExecuteCommand(FtpSession session, StringRequestInfo requestInfo)
        {
            if (!session.Logged)
            {
                return;
            }

            DataConnection dataConnection;

            if (DataConnection.TryOpenDataConnection(session, out dataConnection))
            {
                var port = dataConnection.Port;

                var localAddress = session.AppServer.ExternalLocalAddress;

                if (string.IsNullOrEmpty(localAddress))
                {
                    localAddress = ((IPEndPoint)session.LocalEndPoint).Address.ToString();
                }

                string address = localAddress.Replace('.', ',') + "," + (port >> 8) + "," + (port & 0xFF);
                session.DataConnection = dataConnection;
                session.Send(FtpCoreResource.PassiveEnter_227, address);
            }
            else
            {
                session.Send(FtpCoreResource.DataConnectionCannotOpen_420);
            }
        }
Ejemplo n.º 12
0
        public static AuthorizationRequest analysisAuthorizationReq(StringRequestInfo requestInfo)
        {
            byte[] src = new byte[11];
            for (var x = 0; x < requestInfo.Body.Length; x++)
            {
                src[x] = (byte)Convert.ToChar(x);
            }
            AuthorizationRequest request = new AuthorizationRequest();

            //3字节ID
            byte[] id = new byte[3];
            Array.Copy(src, 0, id, 0, id.Length);
            request.TerminalId = ByteUtils.byteToHexStr(id);
            //1字节电量 0-100
            byte[] power = new byte[1];
            Array.Copy(src, 3, power, 0, power.Length);
            request.Power = power[0].ToString();
            //2字节电压 0-100
            byte[] voltage = new byte[2];
            Array.Copy(src, 3 + 1, voltage, 0, voltage.Length);
            request.Voltage = (((voltage[0] << 8) & 0xff00) + (voltage[1] & 0xff)).ToString();
            //1字节电流 0-100
            byte[] current = new byte[2];
            Array.Copy(src, 3 + 1 + 2, current, 0, current.Length);
            request.Current = (((current[0] << 8) & 0xff00) + (current[1] & 0xff)).ToString();
            //1字节电池温度 0-100
            byte[] temperature = new byte[2];
            Array.Copy(src, 3 + 1 + 2 + 2, temperature, 0, temperature.Length);
            request.Temperature = temperature[0].ToString();
            byte[] info = new byte[1];
            Array.Copy(src, 3 + 1 + 2 + 2 + 2, info, 0, info.Length);
            request.updateAuthorizationRequest = info[0].ToString();
            return(request);
        }
Ejemplo n.º 13
0
        public override void ExecuteCommand(FtpSession session, StringRequestInfo requestInfo)
        {
            if (!session.Logged)
                return;

            session.Send(Environment.OSVersion.ToString());
        }
Ejemplo n.º 14
0
        public override void ExecuteCommand(FtpSession session, StringRequestInfo requestInfo)
        {
            if (!session.Logged)
            {
                return;
            }

            string newfileName = requestInfo.Body;

            if (string.IsNullOrEmpty(newfileName))
            {
                session.SendParameterError();
                return;
            }

            if (session.Context.RenameItemType == ItemType.File)
            {
                if (!session.AppServer.FtpServiceProvider.RenameFile(session.Context, session.Context.RenameFor, newfileName))
                {
                    session.Send(session.Context.Message);
                    return;
                }
            }
            else
            {
                if (!session.AppServer.FtpServiceProvider.RenameFolder(session.Context, session.Context.RenameFor, newfileName))
                {
                    session.Send(session.Context.Message);
                    return;
                }
            }

            session.Send(FtpCoreResource.RenameToOk_250);
        }
Ejemplo n.º 15
0
        public override void ExecuteCommand(FtpSession session, StringRequestInfo requestInfo)
        {
            if (!session.Logged)
                return;

            string newfileName = requestInfo.Body;

            if (string.IsNullOrEmpty(newfileName))
            {
                session.SendParameterError();
                return;
            }

            if (session.Context.RenameItemType == ItemType.File)
            {
                if (!session.AppServer.FtpServiceProvider.RenameFile(session.Context, session.Context.RenameFor, newfileName))
                {
                    session.Send(session.Context.Message);
                    return;
                }
            }
            else
            {
                if (!session.AppServer.FtpServiceProvider.RenameFolder(session.Context, session.Context.RenameFor, newfileName))
                {
                    session.Send(session.Context.Message);
                    return;
                }
            }

            session.Send(FtpCoreResource.RenameToOk_250);
        }
Ejemplo n.º 16
0
        public override void ExecuteCommand(FtpSession session, StringRequestInfo requestInfo)
        {
            if (!session.Logged)
                return;

            if (string.IsNullOrEmpty(session.Context.CurrentPath) || session.Context.CurrentPath == "/")
            {
                session.Send(FtpCoreResource.NotFound_550);
                return;
            }

            string path = StringUtil.GetParentDirectory(session.Context.CurrentPath, '/');

            //No parent path, so it's root
            if (string.IsNullOrEmpty(path))
                path = "/";

            if (session.AppServer.FtpServiceProvider.IsExistFolder(session.Context, path))
            {
                session.Context.CurrentPath = path;
                session.Send(string.Format(FtpCoreResource.ChangeDirectoryUp_250, path));
            }
            else
            {
                if (session.Context.Status == FtpStatus.Error)
                    session.Send(session.Context.Message);
                else
                    session.Send(FtpCoreResource.NotFound_550);
            }
        }
Ejemplo n.º 17
0
        public override void ExecuteCommand(FtpSession session, StringRequestInfo requestInfo)
        {
            if (!session.Logged)
            {
                session.Send(FtpCoreResource.AuthenticationFailed_530);
                return;
            }

            string filename = requestInfo.Body;

            if (string.IsNullOrEmpty(filename))
            {
                session.SendParameterError();
                return;
            }

            long size = session.AppServer.FtpServiceProvider.GetFileSize(session.Context, filename);

            if (session.Context.Status == FtpStatus.Error)
            {
                session.Send(session.Context.Message);
            }
            else
            {
                session.Send(FtpCoreResource.SizeOk_213, size);
            }
        }
Ejemplo n.º 18
0
        public override void ExecuteCommand(FtpSession session, StringRequestInfo requestInfo)
        {
            if (session.AppServer.Certificate == null)
            {
                session.Send(FtpCoreResource.AuthError_504);
                return;
            }

            string ssl = requestInfo.Body;

            switch (ssl)
            {
            case ("SSL"):
                session.SecureProtocol = SslProtocols.Ssl3;
                break;

            case ("SSL2"):
                session.SecureProtocol = SslProtocols.Ssl2;
                break;

            case ("TLS"):
                session.SecureProtocol = SslProtocols.Tls;
                break;

            default:
                session.Send(FtpCoreResource.AuthError_504);
                return;
            }

            session.Send(FtpCoreResource.AuthOk_234, ssl);

            session.AppServer.ResetSessionSecurity(session, session.SecureProtocol);
        }
Ejemplo n.º 19
0
        static void AppServer_NewRequestReceived(MyAppSession session, StringRequestInfo requestInfo)
        {
            Console.WriteLine("收到客户端信息: " + requestInfo.Key + " " + requestInfo.Body);
            //session.Send("\r\n msg:" + requestInfo.Body);
            session.Send(requestInfo.Key);

            //switch (requestInfo.Key.ToUpper())
            //{
            //    case ("ECHO"):
            //        session.Send(requestInfo.Body);
            //        break;
            //    case ("ADD"):
            //        int sum = 0;
            //        requestInfo.Parameters.ToList().ForEach(c => sum += Convert.ToInt32(c));
            //        session.Send(sum.ToString());
            //        break;
            //    case ("MULT"):
            //        var result = 1;
            //        foreach (var factor in requestInfo.Parameters.Select(p => Convert.ToInt32(p)))
            //        {
            //            result *= factor;
            //        }
            //        session.Send(result.ToString());
            //        break;
            //}
        }
Ejemplo n.º 20
0
        private static void appServer_NewRequestReceived(AppSession session, StringRequestInfo requestInfo)
        {
            //Checks are sent back message
            var result = session.TrySend("message received");

            session.Close(CloseReason.ClientClosing);
        }
Ejemplo n.º 21
0
        public override void ExecuteCommand(FtpSession session, StringRequestInfo requestInfo)
        {
            if (session.Logged)
            {
                session.Send(FtpCoreResource.AlreadyLoggedIn_230);
                return;
            }

            string username = requestInfo.Body;

            if (string.IsNullOrEmpty(username))
            {
                session.SendParameterError();
                return;
            }
            else if (string.Compare(username, "anonymous", StringComparison.OrdinalIgnoreCase) == 0)
            {
                session.Send(FtpCoreResource.RequirePasswor_331, username);
                session.Context.UserName = username;
                return;
            }
            else
            {
                session.Send(FtpCoreResource.RequirePasswor_331, username);
                session.Context.UserName = username;
                return;
            }
        }
Ejemplo n.º 22
0
 public override void ExecuteCommand(YourSession session, StringRequestInfo commandData)
 {
     foreach (var p in commandData.Parameters)
     {
         session.SendResponse(p);
     }
 }
Ejemplo n.º 23
0
        private void CheckLogin(StringRequestInfo requestInfo)
        {
            var data = requestInfo.Parameters[0];
            var pass = JsonConvert.DeserializeObject <string>(data);

            if (Setting.AdministratorPwd != pass && Setting.Instance.PasswordMap["conn_front_pwd"] != pass)
            {
                SendData(RemoteCommand.Login, "False", appSession);
            }
            else
            {
                Login = true;
                SendData(RemoteCommand.Login, "OK", appSession);
                Thread.Sleep(100);
                SendFrontPasswordToBack();
                Thread.Sleep(300);
                SendFrontSettingToBack();
                Thread.Sleep(300);
                SendLiveDataToBack();
                Thread.Sleep(300);
                var s1 = DateTime.Now;
                SendCurSessionToBack();
                var span1 = (DateTime.Now - s1).TotalMilliseconds;
                Thread.Sleep(500);
                SendIsGameLockToBack();
                Thread.Sleep(100);
                SendSummationBetRecordToBack();
                Thread.Sleep(800);
                Game.Instance.CoreTimer.StartWebTimer();
            }
        }
Ejemplo n.º 24
0
        public override void ExecuteCommand(RemoteProcessSession session, StringRequestInfo commandData)
        {
            Process[] processes;

            string firstParam = commandData.GetFirstParam();

            if (string.IsNullOrEmpty(firstParam) || firstParam == "*")
            {
                processes = Process.GetProcesses();
            }
            else
            {
                processes = Process.GetProcesses().Where(p =>
                                                         p.ProcessName.IndexOf(firstParam, StringComparison.OrdinalIgnoreCase) >= 0).ToArray();
            }

            StringBuilder sb = new StringBuilder();

            foreach (var p in processes)
            {
                sb.AppendLine(string.Format("{0}\t{1}", p.ProcessName, p.Id));
            }

            sb.AppendLine();

            session.Send(sb.ToString());
        }
Ejemplo n.º 25
0
 public override void ExecuteCommand(YourSession session, StringRequestInfo requestInfo)
 {
     foreach (var p in requestInfo.Parameters)
     {
         session.Send(p);
     }
 }
Ejemplo n.º 26
0
        private void appServer_NewRequestReceived(AppSession session, StringRequestInfo requestInfo)
        {
            LogHelper.Log.Info(" 接收到客户端消息内容S:" + requestInfo.Key);
            session.Send(requestInfo.Body);
            LogHelper.Log.Info(" 发送给客户端的消息:" + requestInfo.Body);

            switch (requestInfo.Key.ToUpper())
            {
            case ("ECHO"):
                session.Send(requestInfo.Body);
                break;

            case ("ADD"):
                session.Send(requestInfo.Parameters.Select(p => Convert.ToInt32(p)).Sum().ToString());
                break;

            case ("MULT"):
                var result = 1;
                foreach (var factor in requestInfo.Parameters.Select(p => Convert.ToInt32(p)))
                {
                    result *= factor;
                }
                session.Send(result.ToString());
                break;
            }
        }
Ejemplo n.º 27
0
        public override void ExecuteCommand(FtpSession session, StringRequestInfo requestInfo)
        {
            if (session.AppServer.Certificate == null)
            {
                session.Send(FtpCoreResource.AuthError_504);
                return;
            }

            string ssl = requestInfo.Body;

            switch (ssl)
            {
                case ("SSL"):
                    session.SecureProtocol = SslProtocols.Ssl3;
                    break;
                case ("SSL2"):
                    session.SecureProtocol = SslProtocols.Ssl2;
                    break;
                case ("TLS"):
                    session.SecureProtocol = SslProtocols.Tls;
                    break;
                default:
                    session.Send(FtpCoreResource.AuthError_504);
                    return;
            }

            session.Send(FtpCoreResource.AuthOk_234, ssl);

            session.AppServer.ResetSessionSecurity(session, session.SecureProtocol);
        }
Ejemplo n.º 28
0
 /// <summary>
 /// 未知的Command
 /// </summary>
 /// <param name="requestInfo"></param>
 protected override void HandleUnknownRequest(StringRequestInfo requestInfo)
 {
     base.HandleUnknownRequest(requestInfo);
     byte[] data = Encoding.UTF8.GetBytes($"UnknownRequest: { requestInfo.Body}");
     base.Send(data, 0, data.Length);
     ConsoleHelper.OutputString("未知命令", requestInfo);
 }
Ejemplo n.º 29
0
        public static StopRealTime analysisStop(StringRequestInfo requestInfo)
        {
            byte[] src = new byte[10];
            for (var x = 0; x < requestInfo.Body.Length; x++)
            {
                src[x] = (byte)Convert.ToChar(x);
            }
            StopRealTime stop = new StopRealTime();

            //3字节ID
            byte[] id = new byte[3];
            Array.Copy(src, 0, id, 0, id.Length);
            stop.TerminalId = ByteUtils.byteToHexStr(id);
            //1字节电量 0-100
            byte[] power = new byte[1];
            Array.Copy(src, 3, power, 0, power.Length);
            stop.Power = power[0].ToString();
            //2字节电压 0-100
            byte[] voltage = new byte[2];
            Array.Copy(src, 3 + 1, voltage, 0, voltage.Length);
            stop.Voltage = (((voltage[0] << 8) & 0xff00) + (voltage[1] & 0xff)).ToString();
            //2字节电流 0-100
            byte[] current = new byte[2];
            Array.Copy(src, 3 + 1 + 2, current, 0, current.Length);
            stop.Current = (((current[0] << 8) & 0xff00) + (current[1] & 0xff)).ToString();
            //2字节电池温度 0-100
            byte[] temperature = new byte[2];
            Array.Copy(src, 3 + 1 + 2 + 2, temperature, 0, temperature.Length);
            stop.Temperature = temperature[0].ToString();
            return(stop);
        }
Ejemplo n.º 30
0
 private void exitCT11Mode(TelnetAppSession AppSession, StringRequestInfo stringRequestInfo)
 {
     //isEnterRuCommandMode = false;
     //isRunningRuCommandMode = false;
     //ruModeFSMData.ruSerialPort.stopForwardRecviThread();
     _fsmData.elevator.Fire(TelnetFSM.Events.GoBack);
 }
Ejemplo n.º 31
0
        public override void ExecuteCommand(FtpSession session, StringRequestInfo requestInfo)
        {
            if (!session.Logged)
            {
                return;
            }

            string filepath = requestInfo.Body;

            if (string.IsNullOrEmpty(filepath))
            {
                session.SendParameterError();
                return;
            }

            if (session.AppServer.FtpServiceProvider.IsExistFile(session.Context, filepath))
            {
                session.Context.RenameFor      = filepath;
                session.Context.RenameItemType = ItemType.File;
                session.Send(FtpCoreResource.RenameForOk_350);
            }
            else if (session.AppServer.FtpServiceProvider.IsExistFolder(session.Context, filepath))
            {
                session.Context.RenameFor      = filepath;
                session.Context.RenameItemType = ItemType.Folder;
                session.Send(FtpCoreResource.RenameForOk_350);
            }
            else
            {
                session.Send(session.Context.Message);
            }
        }
Ejemplo n.º 32
0
        private static void AppServer_NewRequestReceived(MySession session, StringRequestInfo requestInfo)
        {
            session.Send(requestInfo.Body);
            //switch (requestInfo.Key.ToUpper())
            //{
            //    case ("ECHO"):
            //        session.Send(requestInfo.Body);
            //        break;

            //    case ("ADD"):
            //        session.Send(requestInfo.Parameters.Select(p => Convert.ToInt32(p)).Sum().ToString());
            //        break;

            //    case ("MULT"):

            //        var result = 1;

            //        foreach (var factor in requestInfo.Parameters.Select(p => Convert.ToInt32(p)))
            //        {
            //            result *= factor;
            //        }

            //        session.Send(result.ToString());
            //        break;
            //}
        }
Ejemplo n.º 33
0
        //命令执行前调用
        public override void OnCommandExecuting(CommandExecutingContext commandContext)
        {
            try
            {
                StringRequestInfo requestInfo = (StringRequestInfo)commandContext.RequestInfo;

                //TODO: construct the receving casic data
                String deviceId = requestInfo.Parameters[3];
                String pduType  = requestInfo.Parameters[6];

                //print the receving data
                String devType  = new CasicCmd().getDeviceTypeByPdu(pduType);
                String operType = new CasicCmd().getOpeTypeByPdu(pduType);

                if (devType != "集中器")
                {
                    Model.DeviceLogInfo1 log = new Model.DeviceLogInfo1();
                    log.DEVICECODE  = deviceId;
                    log.DEVTYPE     = devType;
                    log.OPERATETYPE = operType;
                    log.LOGTIME     = DateTime.Now;
                    log.MESSAGE     = operType;
                    new BLL.DeviceLog1().insert(log);
                }
            }
            catch (Exception e)
            {
                ((CasicSession)commandContext.Session).Logger.Error(e.Message);
            }
        }
Ejemplo n.º 34
0
 public override void ExecuteCommand(FtpSession session, StringRequestInfo reuquestInfo)
 {
     session.Context.ResetState();
     //Close current data connection?
     session.CloseDataConnection();
     session.Send(FtpCoreResource.AbortOk_226);
 }
Ejemplo n.º 35
0
        public override void ExecuteCommand(BroadcastSession session, StringRequestInfo commandData)
        {
            string message = commandData.Data;

            session.AppServer.BroadcastMessage(session, message);
            session.Send("101 message broadcasted");
        }
Ejemplo n.º 36
0
        public override void ExecuteCommand(FtpSession session, StringRequestInfo requestInfo)
        {
            char typeCode = ' ';

            string newType = requestInfo.GetFirstParam();

            if (!string.IsNullOrEmpty(newType) && newType.Length > 0)
            {
                typeCode = newType[0];
            }

            switch (typeCode)
            {
                case ('A'):
                    session.Context.TransferType = TransferType.A;
                    break;
                case ('E'):
                    session.Context.TransferType = TransferType.E;
                    break;
                case ('I'):
                    session.Context.TransferType = TransferType.I;
                    break;
                case ('L'):
                    session.Context.TransferType = TransferType.L;
                    break;
                default:
                    session.SendParameterError();
                    return;
            }

            session.Send(FtpCoreResource.TypeOk_220, typeCode);
        }
Ejemplo n.º 37
0
        /// <summary>
        /// 实现请求处理
        /// </summary>
        /// <param name="session"></param>
        /// <param name="requestInfo"></param>
        static void appServer_NewRequestReceived(AppSession session, StringRequestInfo requestInfo)
        {
            /*
             *   requestInfo.Key        是请求的命令行用空格分隔开的第一部分
             *   requestInfo.Parameters 是用空格分隔开的其余部分
             *
             *   比如:ADD 1 2
             *   requestInfo.Key是ADD
             *   requestInfo.Parameters是[1,2]
             */

            switch (requestInfo.Key.ToUpper())
            {
            case ("ECHO"):
                session.Send(requestInfo.Body);
                break;

            case ("ADD"):
                session.Send(requestInfo.Parameters.Select(p => Convert.ToInt32(p)).Sum().ToString());
                break;

            case ("MULT"):

                var result = 1;

                foreach (var factor in requestInfo.Parameters.Select(p => Convert.ToInt32(p)))
                {
                    result *= factor;
                }

                session.Send(result.ToString());
                break;
            }
        }
Ejemplo n.º 38
0
        /// <summary>
        /// 实现请求处理.
        /// </summary>
        /// <param name="session"></param>
        /// <param name="requestInfo"></param>
        static void appServer_NewRequestReceived(AppSession session, StringRequestInfo requestInfo)
        {
            // 注意: 这个例子, 是硬编码, switch/case  判断输入的命令.
            switch (requestInfo.Key.ToUpper())
            {
            case ("ECHO"):
                session.Send(requestInfo.Body);
                break;

            case ("ADD"):
                session.Send(requestInfo.Parameters.Select(p => Convert.ToInt32(p)).Sum().ToString());
                break;

            case ("MULT"):

                var result = 1;

                foreach (var factor in requestInfo.Parameters.Select(p => Convert.ToInt32(p)))
                {
                    result *= factor;
                }

                session.Send(result.ToString());
                break;
            }
        }
Ejemplo n.º 39
0
        public override void ExecuteCommand(FtpSession session, StringRequestInfo requestInfo)
        {
            string param = requestInfo.Body;
            if (string.IsNullOrEmpty(requestInfo.Body))
                param = Guid.NewGuid().ToString();

            base.ExecuteCommand(session, new StringRequestInfo(requestInfo.Key, param, new string[]{ }));
        }
Ejemplo n.º 40
0
        public override void ExecuteCommand(FtpSession session, StringRequestInfo requestInfo)
        {
            if (!session.Logged)
                return;

            long offset = requestInfo.Body.ToLong();

            session.Context.Offset = offset;

            session.Send(FtpCoreResource.RestartOk_350, offset);
        }
Ejemplo n.º 41
0
        public override void ExecuteCommand(AppSession session, StringRequestInfo requestInfo)
        {
            var result = 1;

            foreach (var factor in requestInfo.Parameters.Select(p => Convert.ToInt32(p)))
            {
                result *= factor;
            }

            session.Send(result.ToString());
        }
Ejemplo n.º 42
0
        public override void ExecuteCommand(FtpSession session, StringRequestInfo requestInfo)
        {
            if (session.Logged)
            {
                session.Send(FtpCoreResource.AlreadyLoggedIn_230);
                return;
            }

            string password = requestInfo.Body;

            if (string.IsNullOrEmpty(password))
            {
                session.SendParameterError();
                return;
            }

            FtpUser user = null;

            AuthenticationResult result = AuthenticationResult.Success;

            //if (session.Context.IsAnonymous)
            //    user = new Anonymous();
            //else

            result = session.AppServer.FtpServiceProvider.Authenticate(session.Context.UserName, password, out user);

            if (result == AuthenticationResult.Success)
            {
                session.FailedLogInTimes = 0;

                if (session.AppServer.Logon(session.Context, user))
                {
                    session.Send(FtpCoreResource.LoggedIn_230);
                    session.Logged = true;
                }
                else
                {
                    session.Send(FtpCoreResource.ReachedLoginLimit_421);
                    session.Close();
                }
            }
            else
            {
                session.FailedLogInTimes++;
                session.Send(FtpCoreResource.AuthenticationFailed_530);

                //Exceed max allowed failed login times, close the connection
                if(session.FailedLogInTimes >= session.AppServer.MaxFailedLogInTimes)
                    session.Close();
            }
        }
Ejemplo n.º 43
0
        public override void ExecuteCommand(FtpSession session, StringRequestInfo requestInfo)
        {
            if (!session.Logged)
                return;

            if (!string.IsNullOrEmpty(requestInfo.Body))
            {
                if (requestInfo.Body.StartsWith(FtpPath.Root))
                    session.Context.CurrentPath = requestInfo.Body;
                else
                    session.Context.CurrentPath = FtpPath.Combine(session.Context.CurrentPath, requestInfo.Body);
            }

            List<ListItem> list = session.AppServer.FtpServiceProvider.GetList(session.Context);

            if (session.Context.Status == FtpStatus.Error)
            {
                session.Send(session.Context.Message);
                return;
            }

            DataConnection dataConn = session.DataConnection;

            if (dataConn != null && dataConn.RunDataConnection().Wait(60 * 1000))
            {
                session.Send(FtpCoreResource.DataConnectionAccepted_150);

                try
                {
                    dataConn.SendResponse(session.Context, list);
                }
                catch (Exception e)
                {
                    session.Send(FtpCoreResource.DataConnectionCannotOpen_420);
                    session.Logger.Error(e);
                    return;
                }
                finally
                {
                    session.CloseDataConnection();
                }
                
                session.Send(FtpCoreResource.DataTransferComplete_226);
            }
            else
            {
                session.CloseDataConnection();
                session.Send(FtpCoreResource.DataConnectionCannotOpen_420);
            }
        }
Ejemplo n.º 44
0
        public override void ExecuteCommand(FtpSession session, StringRequestInfo requestInfo)
        {
            if (!session.Logged)
                return;

            string filename = requestInfo.Body;

            if (string.IsNullOrEmpty(filename))
            {
                session.SendParameterError();
                return;
            }

            DataConnection dataConn = session.DataConnection;

            if (dataConn.RunDataConnection().Wait(60 * 1000))
            {
                Stream stream = dataConn.GetStream(session.Context);

                try
                {
                    session.Send(FtpCoreResource.DataConnectionAccepted_150);

                    if (session.AppServer.FtpServiceProvider.StoreFile(session.Context, filename, stream))
                        session.Send(FtpCoreResource.DataTransferComplete_226);
                    else
                        session.Send(session.Context.Message);
                }
                catch (SocketException)
                {
                    session.Send(FtpCoreResource.DataConnectionError_426);
                }
                catch (Exception e)
                {
                    session.Logger.Error(e);
                    session.Send(FtpCoreResource.OuputFileError_551);
                }
                finally
                {
                    session.CloseDataConnection();
                }
            }
            else
            {
                session.CloseDataConnection();
                session.Send(FtpCoreResource.DataConnectionCannotOpen_420);
            }
        }
Ejemplo n.º 45
0
        public override void ExecuteCommand(FtpSession session, StringRequestInfo requestInfo)
        {
            if (!session.Logged)
                return;

            string filename = requestInfo.Body;

            if (string.IsNullOrEmpty(filename))
            {
                session.SendParameterError();
                return;
            }

            long size = session.AppServer.FtpServiceProvider.GetFileSize(session.Context, filename);

            if (session.Context.Status == FtpStatus.Error)
                session.Send(session.Context.Message);
            else
                session.Send(FtpCoreResource.SizeOk_213, size);
        }
Ejemplo n.º 46
0
        public override void ExecuteCommand(FtpSession session, StringRequestInfo requestInfo)
        {
            if (!session.Logged)
                return;

            string path = requestInfo.Body;

            if (string.IsNullOrEmpty(path))
            {
                session.SendParameterError();
                return;
            }

            if (!path.StartsWith("/"))
            {
                var context = session.Context;
                var currentPath = context.CurrentPath;

                if (currentPath == "/")
                {
                    path = currentPath + path;
                }
                else
                {
                    path = currentPath + "/" + path;
                }
            }

            if (session.AppServer.FtpServiceProvider.IsExistFolder(session.Context, path))
            {
                session.Context.CurrentPath = path;
                session.Send(FtpCoreResource.ChangeWorkDirOk_250, path);
            }
            else
            {
                if (session.Context.Status == FtpStatus.Error)
                    session.Send(session.Context.Message);
                else
                    session.Send(FtpCoreResource.NotFound_550);
            }
        }
Ejemplo n.º 47
0
        public override void ExecuteCommand(FtpSession session, StringRequestInfo requestInfo)
        {
            string filename = requestInfo.Body;

            if (string.IsNullOrEmpty(filename))
            {
                session.SendParameterError();
                return;
            }

            DateTime mdfTime = session.AppServer.FtpServiceProvider.GetModifyTime(session.Context, filename);

            if (session.Context.Status == FtpStatus.Error)
            {
                session.Send(session.Context.Message);
            }
            else
            {
                session.Send(string.Format(FtpCoreResource.FileOk_213, mdfTime.ToString("yyyyMMddhhmmss")));
            }
        }
Ejemplo n.º 48
0
        public override void ExecuteCommand(FtpSession session, StringRequestInfo requestInfo)
        {
            if (!session.Logged)
                return;

            string foldername = requestInfo.Body;

            if (string.IsNullOrEmpty(foldername))
            {
                session.SendParameterError();
                return;
            }

            if (session.AppServer.FtpServiceProvider.RemoveFolder(session.Context, foldername))
            {
                session.Send(FtpCoreResource.RemoveOk_250, CombinePath(session.Context.CurrentPath, foldername));
            }
            else
            {
                session.Send(session.Context.Message);
            }
        }
Ejemplo n.º 49
0
        public override void ExecuteCommand(FtpSession session, StringRequestInfo requestInfo)
        {
            if (!session.Logged)
                return;

            string filename = requestInfo.Body;

            if (string.IsNullOrEmpty(filename))
            {
                session.SendParameterError();
                return;
            }

            if (session.AppServer.FtpServiceProvider.DeleteFile(session.Context, filename))
            {
                session.Send(FtpCoreResource.DeleteOk_250);
            }
            else
            {
                session.Send(session.Context.Message);
            }
        }
Ejemplo n.º 50
0
        public override void ExecuteCommand(FtpSession session, StringRequestInfo requestInfo)
        {
            if (!session.Logged)
                return;

            if (session.SecureProtocol == SslProtocols.None)
            {
                session.Send(FtpCoreResource.ProtDisabled_431);
                return;
            }

            string level = requestInfo.Body;

            if (string.IsNullOrEmpty(level) || level.Length > 1)
            {
                session.SendParameterError();
                return;
            }

            switch (level[0])
            {
                case ('C'):
                case ('c'):
                    session.Context.DataSecureProtocol = SslProtocols.None;
                    break;
                case ('P'):
                case ('p'):
                    session.Context.DataSecureProtocol = session.SecureProtocol;
                    break;
                default:
                    session.Send(FtpCoreResource.ProtectionLevelUnknow_504);
                    return;
            }

            session.Context.ResetState();
            session.Send(FtpCoreResource.ProtOk_200);
        }
Ejemplo n.º 51
0
        public override void ExecuteCommand(FtpSession session, StringRequestInfo requestInfo)
        {
            if (!session.Logged)
                return;

            string address = requestInfo.GetFirstParam();

            string[] arrAddress = new string[0];

            if (!string.IsNullOrEmpty(address))
            {
                arrAddress = address.Split(',');
            }

            if (arrAddress == null || arrAddress.Length != 6)
            {
                session.SendParameterError();
                return;
            }

            //string ip = arrAddress[0] + "." + arrAddress[1] + "." + arrAddress[2] + "." + arrAddress[3];
            int port = (Convert.ToInt32(arrAddress[4]) << 8) | Convert.ToInt32(arrAddress[5]);

            DataConnection dataConnection;
            if (DataConnection.TryOpenDataConnection(session, port, out dataConnection))
            {
                session.DataConnection = dataConnection;
                session.Send(FtpCoreResource.PortOk_220);
                return;
            }
            else
            {
                session.Send(FtpCoreResource.PortInvalid_552);
                return;
            }
        }
Ejemplo n.º 52
0
 public override void ExecuteCommand(FtpSession session, StringRequestInfo requestInfo)
 {
     session.Send(FtpCoreResource.NoopOk_200);
 }
Ejemplo n.º 53
0
 public override void ExecuteCommand(AppSession session, StringRequestInfo requestInfo)
 {
     session.Send(requestInfo.Body);
 }
Ejemplo n.º 54
0
 public override void ExecuteCommand(AppSession session, StringRequestInfo requestInfo)
 {
     session.Close();
 }
Ejemplo n.º 55
0
 public override void ExecuteCommand(FtpSession session, StringRequestInfo requestInfo)
 {
     session.Send(FtpCoreResource.NotImplement_502);
 }
Ejemplo n.º 56
0
 public override void ExecuteCommand(AppSession session, StringRequestInfo requestInfo)
 {
     session.Send(requestInfo.Body);
     Console.WriteLine("S:" + requestInfo.Body);
 }
Ejemplo n.º 57
0
 public override void ExecuteCommand(AppSession session, StringRequestInfo requestInfo)
 {
     ((MyAppServerA)session.AppServer).DespatchMessage(requestInfo[0], requestInfo[1]);
 }