private static IFtpServerBuilder ConfigureServer(this IFtpServerBuilder builder, FtpOptions options)
        {
            builder = builder
                      .DisableChecks();

            if (options.Connection.Inactivity.Enabled)
            {
                builder = builder
                          .EnableIdleCheck();
                builder.Services
                .Configure <FtpConnectionOptions>(
                    opt => opt.InactivityTimeout = ToTimeSpan(options.Connection.Inactivity.InactivityTimeout));
            }

            if (options.Connection.SocketState.Enabled)
            {
                builder = builder
                          .EnableConnectionCheck();
            }

            if (options.Ftps.Implicit)
            {
                var implicitFtpsCertificate = options.GetCertificate();
                if (implicitFtpsCertificate != null)
                {
                    builder = builder.UseImplicitTls(implicitFtpsCertificate);
                }
            }

            return(builder);
        }
        /// <summary>
        /// Configure authentication.
        /// </summary>
        /// <param name="builder">The FTP server builder.</param>
        /// <param name="options">The options.</param>
        /// <returns>The FTP server builder.</returns>
        public static IFtpServerBuilder ConfigureAuthentication(
            this IFtpServerBuilder builder,
            FtpOptions options)
        {
            if (options.Authentication == MembershipProviderType.Default)
            {
                return(builder.EnableAnonymousAuthentication());
            }

            if ((options.Authentication & MembershipProviderType.Custom) != 0)
            {
                builder.Services.AddSingleton <IMembershipProvider, CustomMembershipProvider>();
            }

#if NETCOREAPP
            if ((options.Authentication & MembershipProviderType.PAM) != 0)
            {
                builder = builder.EnablePamAuthentication();
            }
#endif

            if ((options.Authentication & MembershipProviderType.Anonymous) != 0)
            {
                builder = builder.EnableAnonymousAuthentication();
            }

            return(builder);
        }
        /// <summary>
        /// Uses S3 as file system.
        /// </summary>
        /// <param name="builder">The server builder used to configure the FTP server.</param>
        /// <returns>the server builder used to configure the FTP server.</returns>
        public static IFtpServerBuilder UseS3FileSystem(this IFtpServerBuilder builder)
        {
            builder.Services
            .AddSingleton <IFileSystemClassFactory, S3FileSystemProvider>();

            return(builder);
        }
 public static IFtpServerBuilder EnablePamAuthentication([NotNull] this IFtpServerBuilder builder)
 {
     builder.Services
     .AddSingleton <IMembershipProvider, PamMembershipProvider>()
     .AddSingleton <IPamService, PamService>()
     .AddSingleton <IAuthorizationAction, PamSessionAuthorizationAction>();
     return(builder);
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Uses Google Drive as file system.
 /// </summary>
 /// <param name="builder">The server builder used to configure the FTP server.</param>
 /// <param name="createDriveService">Create the <see cref="DriveService"/> to be used to access the Google Drive API.</param>
 /// <returns>the server builder used to configure the FTP server.</returns>
 public static IFtpServerBuilder UseGoogleDrive(this IFtpServerBuilder builder, Func <IServiceProvider, DriveService> createDriveService)
 {
     builder.Services
     .AddSingleton(createDriveService)
     .AddSingleton <IGoogleDriveServiceProvider, GoogleDriveServiceProvider>()
     .AddSingleton <IFileSystemClassFactory, GoogleDriveFileSystemProvider>();
     return(builder);
 }
        /// <summary>
        /// Uses Azure Blob Storage as file system.
        /// </summary>
        /// <param name="builder">The server builder used to configure the FTP server.</param>
        /// <returns>the server builder used to configure the FTP server.</returns>
        public static IFtpServerBuilder UseAzureStorage(this IFtpServerBuilder builder)
        {
            builder.Services
            .AddSingleton <IFileSystemClassFactory, AzureStorageFileSystemProvider>()
            .AddSingleton <IMembershipProvider, AzureStorageMembershipProvider>()
            ;

            return(builder);
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Uses Google Drive as file system.
 /// </summary>
 /// <param name="builder">The server builder used to configure the FTP server.</param>
 /// <param name="httpClientInitializer">The HTTP client initializer.</param>
 /// <param name="applicationName">The application name.</param>
 /// <returns>the server builder used to configure the FTP server.</returns>
 public static IFtpServerBuilder UseGoogleDrive(this IFtpServerBuilder builder, IConfigurableHttpClientInitializer httpClientInitializer, string applicationName = "FTP Server")
 {
     return(builder.UseGoogleDrive(
                _ => new DriveService(
                    new BaseClientService.Initializer()
     {
         ApplicationName = applicationName,
         HttpClientInitializer = httpClientInitializer,
     })));
 }
        public static IFtpServerBuilder UsePamUserHome(
            [NotNull] this IFtpServerBuilder builder,
            [CanBeNull] Action <PamAccountDirectoryQueryOptions> configure = null)
        {
            builder.Services.AddSingleton <IAccountDirectoryQuery, PamAccountDirectoryQuery>();
            if (configure != null)
            {
                builder.Services.Configure(configure);
            }

            return(builder);
        }
        /// <summary>
        /// Uses a single root for all users.
        /// </summary>
        /// <param name="builder">The server builder used to configure the FTP server.</param>
        /// <param name="configure">Optional service configuration.</param>
        /// <returns>the server builder used to configure the FTP server.</returns>
        public static IFtpServerBuilder UseSingleRoot(
            this IFtpServerBuilder builder,
            Action <SingleRootWithoutHomeAccountDirectoryQueryOptions> configure = null)
        {
            builder.Services.AddSingleton <IAccountDirectoryQuery, SingleRootWithoutHomeAccountDirectoryQuery>();
            if (configure != null)
            {
                builder.Services.Configure(configure);
            }

            return(builder);
        }
        /// <summary>
        /// Uses the user name as root directory (NOT ITS HOME DIRECTORY!).
        /// </summary>
        /// <remarks>
        /// This might not be useful in a production system.
        /// </remarks>
        /// <param name="builder">The server builder used to configure the FTP server.</param>
        /// <param name="configure">Optional service configuration.</param>
        /// <returns>the server builder used to configure the FTP server.</returns>
        public static IFtpServerBuilder UseRootPerUser(
            this IFtpServerBuilder builder,
            Action <RootPerUserAccountDirectoryQueryOptions>?configure = null)
        {
            builder.Services.AddSingleton <IAccountDirectoryQuery, RootPerUserAccountDirectoryQuery>();
            if (configure != null)
            {
                builder.Services.Configure(configure);
            }

            return(builder);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Remove all connection-related checks.
        /// </summary>
        /// <param name="builder">The FTP server builder.</param>
        /// <returns>The same FTP server builder.</returns>
        public static IFtpServerBuilder DisableChecks(
            this IFtpServerBuilder builder)
        {
            var servicesToRemove = builder.Services
                                   .Where(x => x.ServiceType == typeof(IFtpConnectionCheck))
                                   .ToList();

            foreach (var serviceDescriptor in servicesToRemove)
            {
                builder.Services.Remove(serviceDescriptor);
            }

            return(builder);
        }
Ejemplo n.º 12
0
 public static IFtpServerBuilder UseImplicitTls(this IFtpServerBuilder builder, X509Certificate certificate)
 {
     builder.Services
     .AddSingleton(new ImplicitFtpsControlConnectionStreamAdapterOptions(certificate))
     .AddSingleton <IFtpControlStreamAdapter, ImplicitFtpsControlConnectionStreamAdapter>()
     .AddSingleton <IFtpConnectionConfigurator, AuthTlsConfigurator>()
     .Configure <AuthTlsOptions>(
         options =>
     {
         options.ServerCertificate = certificate;
         options.ImplicitFtps      = true;
     });
     return(builder);
 }
Ejemplo n.º 13
0
        private static IFtpServerBuilder DisableCheck <TCheck>(
            this IFtpServerBuilder builder)
            where TCheck : IFtpConnectionCheck
        {
            var servicesToRemove = builder.Services
                                   .Where(x => x.ServiceType == typeof(IFtpConnectionCheck))
                                   .Where(x => x.ImplementationType == typeof(TCheck))
                                   .ToList();

            foreach (var serviceDescriptor in servicesToRemove)
            {
                builder.Services.Remove(serviceDescriptor);
            }

            return(builder);
        }
Ejemplo n.º 14
0
        private static IFtpServerBuilder Configure(IFtpServerBuilder builder, TestFtpServerOptions options)
        {
            switch (options.MembershipProviderType)
            {
            case MembershipProviderType.Anonymous:
                return(builder.EnableAnonymousAuthentication());

            case MembershipProviderType.Custom:
                builder.Services.AddSingleton <IMembershipProvider, CustomMembershipProvider>();
                break;

            default:
                throw new InvalidOperationException($"Unknown membership provider {options.MembershipProviderType}");
            }

            return(builder);
        }
Ejemplo n.º 15
0
        private static IFtpServerBuilder ConfigureServer(this IFtpServerBuilder builder, FtpOptions options)
        {
            builder = builder
                      .DisableChecks();

            if (options.Connection.Inactivity.Enabled)
            {
                builder = builder
                          .EnableIdleCheck();
                builder.Services
                .Configure <FtpConnectionOptions>(
                    opt => opt.InactivityTimeout = ToTimeSpan(options.Connection.Inactivity.InactivityTimeout));
            }

            if (options.Connection.SocketState.Enabled)
            {
                builder = builder
                          .EnableConnectionCheck();
            }

            return(builder);
        }
Ejemplo n.º 16
0
 private static IFtpServerBuilder Configure(IFtpServerBuilder builder)
 {
     return(builder.EnableAnonymousAuthentication());
 }
Ejemplo n.º 17
0
 /// <inheritdoc />
 protected override IFtpServerBuilder Configure(IFtpServerBuilder builder)
 {
     return(builder
            .UseSingleRoot()
            .UseInMemoryFileSystem());
 }
Ejemplo n.º 18
0
 public UpdateDirector(IFtpServerBuilder builder)
 {
     _serverBuilder = builder;
 }
Ejemplo n.º 19
0
 public static IFtpServerBuilder UseCustomServerDemo(this IFtpServerBuilder builder)
 {
     builder.Services.AddSingleton <IFileSystemClassFactory, CustomServerDemoProvider>();
     return(builder);
 }
Ejemplo n.º 20
0
 /// <summary>
 /// Adds the default checks for the connection.
 /// </summary>
 /// <param name="builder">The FTP server builder.</param>
 /// <returns>The same FTP server builder.</returns>
 public static IFtpServerBuilder EnableDefaultChecks(
     this IFtpServerBuilder builder)
 {
     return(builder.EnableConnectionCheck().EnableIdleCheck());
 }
Ejemplo n.º 21
0
 /// <summary>
 /// Enables anonymous authentication.
 /// </summary>
 /// <param name="builder">The server builder used to configure the FTP server.</param>
 /// <returns>the server builder used to configure the FTP server.</returns>
 public static IFtpServerBuilder EnableAnonymousAuthentication(this IFtpServerBuilder builder)
 {
     builder.Services.AddSingleton <IMembershipProvider, AnonymousMembershipProvider>();
     return(builder);
 }
Ejemplo n.º 22
0
 /// <summary>
 /// Adds check for the connections that tests whether the underlying TCP connection is still established.
 /// </summary>
 /// <param name="builder">The FTP server builder.</param>
 /// <returns>The same FTP server builder.</returns>
 public static IFtpServerBuilder EnableConnectionCheck(
     this IFtpServerBuilder builder)
 {
     builder.Services.AddSingleton <IFtpConnectionCheck, FtpConnectionEstablishedCheck>();
     return(builder);
 }
Ejemplo n.º 23
0
 /// <summary>
 /// Removes check for the connections that tests whether the underlying TCP connection is still established.
 /// </summary>
 /// <param name="builder">The FTP server builder.</param>
 /// <returns>The same FTP server builder.</returns>
 public static IFtpServerBuilder DisableConnectionCheck(
     this IFtpServerBuilder builder)
 {
     return(builder.DisableCheck <FtpConnectionEstablishedCheck>());
 }