示例#1
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);
        }
示例#2
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;
            }
        }
示例#3
0
        public override void ExecuteCommand(RemoteProcessSession session, StringRequestInfo commandData)
        {
            var server = session.AppServer;

            string firstParam = commandData.GetFirstParam();

            if (string.IsNullOrEmpty(firstParam))
            {
                session.Send("Invalid parameter!");
                return;
            }

            var param = commandData[1];

            if ("list".Equals(firstParam, StringComparison.OrdinalIgnoreCase))
            {
                StringBuilder sb = new StringBuilder();
                foreach (var p in server.GetFrozedProcesses())
                {
                    sb.AppendLine(p);
                }
                sb.AppendLine();

                session.Send(sb.ToString());
                return;
            }
            else if ("add".Equals(firstParam, StringComparison.OrdinalIgnoreCase))
            {
                if (string.IsNullOrEmpty(param))
                {
                    session.Send("Invalid parameter!");
                    return;
                }

                server.AddFrozedProcess(param);
                session.Send(string.Format("Frozed process {0} has been added!", param));
                return;
            }
            else if ("remove".Equals(firstParam, StringComparison.OrdinalIgnoreCase))
            {
                if (string.IsNullOrEmpty(param))
                {
                    session.Send("Invalid parameter!");
                    return;
                }

                server.RemoveFrozedProcess(param);
                session.Send(string.Format("Frozed process {0} has been removed!", param));
                return;
            }
            else if ("clear".Equals(firstParam, StringComparison.OrdinalIgnoreCase))
            {
                server.ClearFrozedProcess();
                session.Send("All frozed process have been removed!");
                return;
            }
            else if ("stop".Equals(firstParam, StringComparison.OrdinalIgnoreCase))
            {
                server.StopFroze();
                session.Send("Frozing has been stopped!");
                return;
            }
            else if ("start".Equals(firstParam, StringComparison.OrdinalIgnoreCase))
            {
                server.StartFroze();
                session.Send("Frozing has been started!");
                return;
            }
        }
 public void runAction(TelnetAppSession AppSession, StringRequestInfo stringRequestInfo)
 {
     if (stringRequestInfo.Key.Length != 0)
     {
         if (stringRequestInfo.Key == "ExitIcolishMode")
         {
             exitIcolishMode(AppSession, stringRequestInfo);
         }
         if (!_isEnterMode)
         {
             if (stringRequestInfo.Key == "OpenVirtualChannel")
             {
                 RunTimeError runTimeError = new RunTimeError();
                 string       cpriPort     = stringRequestInfo.GetFirstParam();
                 string       comPortName  = "";
                 int          objectID     = 0;
                 if (!ComportDic.ContainsKey(cpriPort))
                 {
                     if (!openVirtualChannel(AppSession, stringRequestInfo, out objectID))
                     {
                         return;
                     }
                 }
                 ComportDic[cpriPort].Second = objectID;
                 comPortName = (string)ComportDic[cpriPort].First;
                 if (isOpen)
                 {
                     ruSerialPort.stopForwardRecviThread();
                     ruSerialPort.close();
                     isOpen = false;
                 }
                 if (openComPort(runTimeError, comPortName))
                 {
                     isOpen = true;
                     ruSerialPort.startForwardRecviThread(AppSession);
                     _isEnterMode = true;
                 }
                 else
                 {
                     AppSession.Send(runTimeError.Errordescription + "\n&");
                 }
             }
             else
             {
                 AppSession.Send("please OpenVirtualChannel: OpenVirtualChannel [CpriPort] \r\n\t like:  OpenVirtualChannel 1A \n&");
             }
         }
         else
         {
             string cmd = "";
             if (stringRequestInfo.GetFirstParam().Length > 0)
             {
                 cmd = stringRequestInfo.Key + " " + stringRequestInfo.Body;
             }
             else
             {
                 cmd = stringRequestInfo.Key;
             }
             ruSerialPort.send(cmd);
         }
     }
     else
     {
         AppSession.sendNoNewLine("&");
     }
 }