Exemplo n.º 1
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();
        }
Exemplo n.º 2
-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");
                }
            }
        }