示例#1
0
        public void StartImpl()
        {
            var baseDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

            var dir          = ConfigurationManager.AppSettings["dir"];
            var port         = ParseUshort(ConfigurationManager.AppSettings["port"]);
            var dataPortFrom = ParseUshort(ConfigurationManager.AppSettings["dataPortFrom"]);
            var dataPortTo   = ParseUshort(ConfigurationManager.AppSettings["dataPortTo"]);

            if (!Path.IsPathRooted(dir))
            {
                dir = Path.Combine(baseDir, dir);
            }

            var cfg = new FtpHostConfig
            {
                Dir          = dir,
                Port         = port,
                DataPortFrom = dataPortFrom,
                DataPortTo   = dataPortTo,
            };

            var auth = ConfigurationManager.GetSection("auth") as NameValueCollection;

            foreach (string user in auth)
            {
                cfg.Credentials.Add(user, auth[user]);
            }

            var host = new FTPHost(cfg);

            host.Listen();
        }
示例#2
0
        static void Main(string[] args)
        {
            var baseDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            var builder = new ConfigurationBuilder()
                          .SetBasePath(baseDir)
                          .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
            ;
            var configuration = builder.Build();

            var dir          = configuration["dir"];
            var port         = ParseUshort(configuration["port"]);
            var dataPortFrom = ParseUshort(configuration["dataPortFrom"]);
            var dataPortTo   = ParseUshort(configuration["dataPortTo"]);

            if (!Path.IsPathRooted(dir))
            {
                dir = Path.Combine(baseDir, dir);
            }

            var cfg = new FtpHostConfig
            {
                Dir          = dir,
                Port         = port,
                DataPortFrom = dataPortFrom,
                DataPortTo   = dataPortTo,
            };

            var auth = configuration.GetSection("auth");

            foreach (var item in auth.GetChildren())
            {
                cfg.Credentials.Add(item.Key, item.Value);
            }

            var host = new FTPHost(cfg);

            host.Listen();
            Console.ReadLine();
        }