Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

InMemoryFileSystem documentation #160

Open
piersdeseilligny opened this issue Jan 31, 2024 · 2 comments
Open

InMemoryFileSystem documentation #160

piersdeseilligny opened this issue Jan 31, 2024 · 2 comments

Comments

@piersdeseilligny
Copy link

I'm just creating this issue because as far as I can tell, there's no documentation or examples anywhere of how to use the InMemoryFileSystem, and it's not extremely clear how to do so - would it be possible to get some sample code of a very simple setup, just to get an idea of what's required to provide a "virtual" file system to a client, and to receive incoming requests and files?

Thanks for such a great extension!
Piers

@dingetje
Copy link

I second this request

@ChairmanMawh
Copy link

ChairmanMawh commented Jul 12, 2024

There didn't seem to be much to it when I gave it a go. My Main looked like the one from the DotNetFileSystem example, except with swapped names for InMemory. I chose to allow an anonymous access:

static async Task Main(string[] args)
{
    // Setup dependency injection
    var services = new ServiceCollection();

    // Add FTP server services
    // AnonymousMembershipProvider = allow only anonymous logins
    services.AddFtpServer(builder => builder
        .UseInMemoryFileSystem() 
        .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
        await ftpServerHost.StartAsync();

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

        // Stop the FTP server
        await ftpServerHost.StopAsync();
    }
}

That was pretty much it, I ran it, connected with filezilla and uploaded stuff, i could see it, when I restarted the server it was gone (as you might expect!)

I took a quick look into the code (download it from this repo and have a read of the comments in InMemory project) to work out e.g. that

services.Configure<InMemoryFileSystemOptions>(opt => opt.KeepAnonymousFileSystem = false);

Means the server will throw away uploaded files when the anonymous user disconnects/reconnects, whereas setting it to true means the files will be kept across client disconnect/reconnect cycles (but not server restarts)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants