public FTPserver() { ftpserver = new Server(); ftpserver.LocalEndPoint = new System.Net.IPEndPoint(IPAddress.Any, int.Parse(Statics.FTPServer_Port_num)); ftpserver.LogHandler = new DefaultLogHandler(false); Thread clientThread = new Thread(new ThreadStart(Run)); clientThread.Start(); }
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); } }
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; }
public void kill() { ftpserver.Stop(); ftpserver = null; Log.log_info("FTP Server Stoped"); }