FubarDevelopment / FtpServer

Portable FTP server written in .NET
http://fubardevelopment.github.io/FtpServer/
MIT License
472 stars 161 forks source link

Abnormal operation of DEMO program #152

Open snikeguo opened 1 year ago

snikeguo commented 1 year ago

OS:win10

public static void Main(string[] args) 
        {
            var services = new ServiceCollection();

            // use %TEMP%/TestFtpServer as root folder
            /*services.Configure<DotNetFileSystemOptions>(opt => opt
                .RootPath = Directory.GetCurrentDirectory());*/

            // Add FTP server services
            // DotNetFileSystemProvider = Use the .NET file system functionality
            // AnonymousMembershipProvider = allow only anonymous logins
            services.AddFtpServer(builder => builder
                .UseUnixFileSystem() // Use the .NET file system functionality
                .EnableAnonymousAuthentication()); // allow anonymous logins

            // Configure the FTP server
            services.Configure<FtpServerOptions>(opt => opt.ServerAddress = "127.0.0.1");

            // Build the service provider
            using (var serviceProvider = services.BuildServiceProvider())
            {
                // Initialize the FTP server
                var ftpServerHost = serviceProvider.GetRequiredService<IFtpServerHost>();

                // Start the FTP server
                ftpServerHost.StartAsync(CancellationToken.None).Wait();

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

                // Stop the FTP server
                ftpServerHost.StopAsync(CancellationToken.None).Wait();
            }

        }

run result:

System.InvalidOperationException:“Unable to resolve service for type 'Microsoft.Extensions.Logging.ILoggerFactory' while attempting to activate 'FubarDev.FtpServer.FileSystem.Unix.UnixFileSystemProvider'.”

After modifying the UseDotNetFileSystem method to the UseUnixFileSystem method, I received an error message.

I developed a device that is not a Udisk but a custom USB device. Then I developed the c#library, which provides interfaces such as mkdir, open, write, close, etc. The library has a file system catalog style of UNIX (e.g. /home/test), and I want to modify the code of FubarDev.FtpServer.FileSystem.Unix:

Eg:

Public Task UnlinkAsync (IUnixFileSystemEntry entry, CancellationToken cancellationToken)
{
FatFsFuseLib.Unlink(....);
}
fubar-coder commented 1 year ago

You've found a bug 👍

The line ILoggerFactory? loggerFactory should read ILoggerFactory? loggerFactory = null.

You can also add logging to your app (https://learn.microsoft.com/en-us/dotnet/api/microsoft.extensions.dependencyinjection.loggingservicecollectionextensions.addlogging?view=dotnet-plat-ext-7.0&viewFallbackFrom=net-6.0).