Example #1
0
        private async Task CommandPortAsync(string parameter)
        {
            var paramSegs = parameter.Split(',');

            if (paramSegs.Length != 6)
            {
                await ReplyAsync(
                    FtpReplyCode.SyntaxErrorInParametersOrArguments,
                    "Syntax error, count of comma incorrect");

                return;
            }
            try
            {
                var       bytes      = paramSegs.Select(x => byte.Parse(x)).ToArray();
                IPAddress remoteIP   = new IPAddress(new ArraySegment <byte>(bytes, 0, 4).ToArray());
                int       remotePort = (bytes[4] << 8) | bytes[5];
                userActiveDataPort = remotePort;
                userActiveIP       = remoteIP;
                userActiveProtocal = 1;
                dataConnectionMode = DataConnectionMode.Active;
                await dataConnection.ConnectActiveAsync(userActiveIP, userActiveDataPort, userActiveProtocal);
                await ReplyAsync(FtpReplyCode.CommandOkay, "Data connection established");

                return;
            }
            catch
            {
                await ReplyAsync(
                    FtpReplyCode.SyntaxErrorInParametersOrArguments,
                    "Syntax error, number format incorrect");

                return;
            }
        }
Example #2
0
        private async Task CommandEpsvAsync(string parameter)
        {
            int port;

            try
            {
                if (string.IsNullOrEmpty(parameter))
                {
                    port = dataConnection.Listen().Port;
                }
                else
                {
                    var protocal = int.Parse(parameter);
                    port = dataConnection.ExtendedListen(protocal);
                }
            }
            catch (FormatException)
            {
                await ReplyAsync(FtpReplyCode.SyntaxErrorInParametersOrArguments, "Protocal ID incorrect.");

                return;
            }
            catch (NotSupportedException)
            {
                var supportedProtocalString =
                    string.Join(",", dataConnection.SupportedPassiveProtocal.Select(x => x.ToString()));
                await ReplyAsync(FtpReplyCode.NotSupportedProtocal, $"Protocal not supported, use({supportedProtocalString})");

                return;
            }
            dataConnectionMode = DataConnectionMode.ExtendedPassive;
            await ReplyAsync(
                FtpReplyCode.EnteringEpsvMode,
                string.Format("Entering extended passive mode (|||{0}|).", port));
        }
Example #3
0
 private void Initialize(System.Net.IPAddress address, int port)
 {
     this.p_Address                  = address;
     this.p_Port                     = port;
     this.p_DataConnectionMode       = DataConnectionMode.Passive;
     this.p_PassiveConnectionCommand = "P@SW";
     this.p_DataType                 = DataType.Binary;
     this.p_DataPort                 = 22;
     this.p_IsOpened                 = false;
 }
Example #4
0
        private async Task CommandPasvAsync()
        {
            var localEP = dataConnection.Listen();
            var ipBytes = localEP.Address.GetAddressBytes();

            if (ipBytes.Length != 4)
            {
                throw new Exception();
            }
            var passiveEPString =
                string.Format(
                    "{0},{1},{2},{3},{4},{5}",
                    ipBytes[0],
                    ipBytes[1],
                    ipBytes[2],
                    ipBytes[3],
                    (byte)(localEP.Port / 256),
                    (byte)(localEP.Port % 256));

            dataConnectionMode = DataConnectionMode.Passive;
            await ReplyAsync(FtpReplyCode.EnteringPassiveMode, "Enter Passive Mode (" + passiveEPString + ")");
        }
Example #5
0
        private async Task CommandEprtAsync(string parameter)
        {
            if (string.IsNullOrEmpty(parameter))
            {
                await ReplyAsync(
                    FtpReplyCode.SyntaxErrorInParametersOrArguments,
                    "Syntax error, parameter is empty");

                return;
            }

            var seperator = parameter[0];
            var paramSegs = parameter.Split(seperator);

            if (paramSegs.Length != 5)
            {
                await ReplyAsync(
                    FtpReplyCode.SyntaxErrorInParametersOrArguments,
                    "Syntax error, count of segments incorrect");

                return;
            }

            int remoteProtocal;

            if (!int.TryParse(paramSegs[1], out remoteProtocal))
            {
                await ReplyAsync(
                    FtpReplyCode.SyntaxErrorInParametersOrArguments,
                    "Protocal ID incorrect");

                return;
            }

            IPAddress remoteIP;
            int       remotePort;

            try
            {
                remoteIP   = IPAddress.Parse(paramSegs[2]);
                remotePort = int.Parse(paramSegs[3]);
            }
            catch (Exception)
            {
                await ReplyAsync(
                    FtpReplyCode.SyntaxErrorInParametersOrArguments,
                    "IP address or port number incorrect.");

                return;
            }
            userActiveDataPort = remotePort;
            userActiveIP       = remoteIP;
            userActiveProtocal = remoteProtocal;

            dataConnectionMode = DataConnectionMode.ExtendedPassive;
            try
            {
                await dataConnection.ConnectActiveAsync(userActiveIP, userActiveDataPort, userActiveProtocal);
            }
            catch (NotSupportedException)
            {
                var supportedProtocalString =
                    string.Join(",", dataConnection.SupportedActiveProtocal.Select(x => x.ToString()));
                await ReplyAsync(FtpReplyCode.NotSupportedProtocal, $"Protocal not supported, use({supportedProtocalString})");

                return;
            }

            await ReplyAsync(FtpReplyCode.CommandOkay, "Data connection established");
        }
Example #6
0
        /// <summary>
        /// 构造函数 赋值
        /// </summary>
        /// <param name="connectionString">链接字符串</param>
        /// <param name="dbType">数据库类型</param>
        /// <param name="isTran">是否启用事务</param>
        public DbExecutor(string connectionString, DatabaseType dbType = DatabaseType.SqlServer, DataConnectionMode connMode = DataConnectionMode.None, IsolationLevel tranLevel = IsolationLevel.Unspecified)
        {
            this.DBType = dbType;
            conn        = this.CreateDbConnection(connectionString);

            if (tranLevel != IsolationLevel.Unspecified)
            {
                conn.Open();
                tran = conn.BeginTransaction(tranLevel);
            }
        }
Example #7
0
 internal static DbExecutor CreateExecutor(string connectionString, DatabaseType dbType = DatabaseType.SqlServer, DataConnectionMode connMode = DataConnectionMode.None, IsolationLevel tranLevel = IsolationLevel.Unspecified)
 {
     return(new DbExecutor(connectionString, dbType, connMode, tranLevel));
 }