public bool Start(string rootDirectory, int port = 21)
        {
            lock (_lock)
            {
                if (_state == STATE.STOPPED)
                {
                    _server                   = new mooftpserv.Server();
                    _server.LogHandler        = new LogHandler(this);
                    _server.FileSystemHandler = new FileSystemHandler(rootDirectory);
                    try
                    {
                        Task.Run(() => { _server.Run(); });
                        _state = STATE.STARTED;
                    }
                    catch (Exception ex)
                    {
                        Console.Error.WriteLine(ex.Message);
                    }
                }

                return(_state == STATE.STARTED);
            }
        }
Exemple #2
0
        public static int Main(string[] args)
        {
            bool verbose = false;
            bool anyPeer = false;
            int  port    = -1;
            int  buffer  = -1;

            // process args
            for (int i = 0; i < args.Length; ++i)
            {
                if (args[i] == "-h" || args[i] == "--help")
                {
                    Console.Out.WriteLine("Usage: <program> [-v|--verbose] [-p|--port <port>] [-b|--buffer <kbsize>] [-a|--any-peer]");
                    return(0);
                }
                else if (args[i] == "-v" || args[i] == "--verbose")
                {
                    verbose = true;
                }
                else if (args[i] == "-a" || args[i] == "--any-peer")
                {
                    anyPeer = true;
                }
                else if (args[i] == "-p" || args[i] == "--port")
                {
                    if (i == args.Length - 1)
                    {
                        Console.Error.WriteLine("Too few arguments for {0}", args[i]);
                        return(1);
                    }

                    port = ParseNumber(args[i], args[i + 1]);
                    if (port == -1)
                    {
                        Console.Error.WriteLine("Invalid value for '{0}': {1}", args[i], args[i + 1]);
                        return(1);
                    }

                    ++i;
                }
                else if (args[i] == "-b" || args[i] == "--buffer")
                {
                    if (i == args.Length - 1)
                    {
                        Console.Error.WriteLine("Too few arguments for {0}", args[i]);
                        return(1);
                    }

                    buffer = ParseNumber(args[i], args[i + 1]);
                    if (buffer == -1)
                    {
                        Console.Error.WriteLine("Invalid value for '{0}': {1}", args[i], args[i + 1]);
                        return(1);
                    }

                    ++i;
                }
                else
                {
                    Console.Error.WriteLine("Unknown argument '{0}'", args[i]);
                    return(1);
                }
            }

            Server srv = new Server();

            srv.LogHandler  = new DefaultLogHandler(verbose);
            srv.AuthHandler = new DefaultAuthHandler(anyPeer);

            if (port != -1)
            {
                srv.LocalPort = port;
            }

            if (buffer != -1)
            {
                srv.BufferSize = buffer * 1024; // in KB
            }
            Console.Out.WriteLine("Starting server on {0}", srv.LocalEndPoint);

            try {
                srv.Run();
            } catch (Exception ex) {
                Console.Error.WriteLine(ex.Message);
                return(1);
            }

            return(0);
        }
Exemple #3
0
        public static int Main(string[] args)
        {
            bool verbose = false;
            int port = -1;
            int buffer = -1;

            // process args
            for (int i = 0; i < args.Length; ++i) {
                if (args[i] == "-h" || args[i] == "--help") {
                    Console.Out.WriteLine("Usage: <program> [-v|--verbose] [-p|--port <port>] [-b|--buffer <kbsize>]");
                    return 0;
                } else if (args[i] == "-v" || args[i] == "--verbose") {
                    verbose = true;
                } else if (args[i] == "-p" || args[i] == "--port") {
                    if (i == args.Length - 1) {
                        Console.Error.WriteLine("Too few arguments for {0}", args[i]);
                        return 1;
                    }

                    port = ParseNumber(args[i], args[i + 1]);
                    if (port == -1) {
                        Console.Error.WriteLine("Invalid value for '{0}': {1}", args[i], args[i + 1]);
                        return 1;
                    }

                    ++i;
                } else if (args[i] == "-b" || args[i] == "--buffer") {
                    if (i == args.Length - 1) {
                        Console.Error.WriteLine("Too few arguments for {0}", args[i]);
                        return 1;
                    }

                    buffer = ParseNumber(args[i], args[i + 1]);
                    if (buffer == -1) {
                        Console.Error.WriteLine("Invalid value for '{0}': {1}", args[i], args[i + 1]);
                        return 1;
                    }

                    ++i;
                } else {
                    Console.Error.WriteLine("Unknown argument '{0}'", args[i]);
                    return 1;
                }
            }

            Server srv = new Server();

            srv.LogHandler = new DefaultLogHandler(verbose);

            if (port != -1)
                srv.LocalPort = port;

            if (buffer != -1)
                srv.BufferSize = buffer * 1024; // in KB

            Console.Out.WriteLine("Starting server on {0}", srv.LocalEndPoint);

            try {
                srv.Run();
            } catch (Exception ex) {
                Console.Error.WriteLine(ex.Message);
                return 1;
            }

            return 0;
        }