Start() public method

Starts the FTP server in the background
public Start ( ) : void
return void
Ejemplo n.º 1
0
        public FtpServer(IFileSystem sys, string host = "127.0.0.1", int port = 21)
        {
            var fsp = new FtpSystemFactory(() => new FtpSystem(sys));
            var msp = new VirtualMemberProvider();
            var ass = typeof(Server).Assembly;
            var cmd = new AssemblyFtpCommandHandlerFactory(ass, new Assembly[0]);

            server            = new Server(fsp, msp, host, port, cmd);
            server.LogManager = new FtpLogManager();
            server.Start();
        }
Ejemplo n.º 2
0
        public void TestCreated()
        {
            var host = "127.0.0.1";

            // allow only anonymous logins
            var membershipProvider = new AnonymousMembershipProvider();

            // use %TEMP%/TestFtpServer as root folder
            var fsProvider = new DotNetFileSystemProvider(Path.Combine(Path.GetTempPath(), "TestFtpServer"), false);

            // Initialize the FTP server
            var ftpServer = new FtpServer(fsProvider, membershipProvider, host);

            // Start the FTP server
            ftpServer.Start();

            VerifyListing(host, "anonymous", "*****@*****.**");

            //Console.WriteLine("Press ENTER/RETURN to close the test application.");
            //Console.ReadLine();

            // Stop the FTP server
            ftpServer.Stop();
        }
Ejemplo n.º 3
-1
        private static void Main()
        {
            // Load server certificate
            var cert = new X509Certificate2("test.pfx");
            AuthTlsCommandHandler.ServerCertificate = cert;

            // Only allow anonymous login
            var membershipProvider = new AnonymousMembershipProvider(new NoValidation());

            // Use the .NET file system
            var fsProvider = new DotNetFileSystemProvider(Path.Combine(Path.GetTempPath(), "TestFtpServer"));

            // Use all commands from the FtpServer assembly and the one(s) from the AuthTls assembly
            var commandFactory = new AssemblyFtpCommandHandlerFactory(typeof(FtpServer).Assembly, typeof(AuthTlsCommandHandler).Assembly);

            // Initialize the FTP server
            using (var ftpServer = new FtpServer(fsProvider, membershipProvider, "127.0.0.1", Port, commandFactory)
            {
                DefaultEncoding = Encoding.ASCII,
                LogManager = new FtpLogManager(),
            })
            {
#if USE_FTPS_IMPLICIT
                // Use an implicit SSL connection (without the AUTHTLS command)
                ftpServer.ConfigureConnection += (s, e) =>
                {
                    var sslStream = new FixedSslStream(e.Connection.OriginalStream);
                    sslStream.AuthenticateAsServer(cert);
                    e.Connection.SocketStream = sslStream;
                };
#endif

                // Create the default logger
                var log = ftpServer.LogManager?.CreateLog(typeof(Program));

                try
                {
                    // Start the FTP server
                    ftpServer.Start();
                    Console.WriteLine("Press ENTER/RETURN to close the test application.");
                    Console.ReadLine();

                    // Stop the FTP server
                    ftpServer.Stop();
                }
                catch (Exception ex)
                {
                    log?.Error(ex, "Error during main FTP server loop");
                }
            }
        }