GithubHelp home page GithubHelp logo

Comments (8)

fubar-coder avatar fubar-coder commented on August 20, 2024

Implement IAccountDirectoryQuery and add it as "singleton" service.

from ftpserver.

aavanesov avatar aavanesov commented on August 20, 2024

Thank you for your clarifications. But unfortunatelly, it looks like GetDirectories of IAccountDirectoryQuery is setting the relative path starting from the root path. Is there a way to override the root path completly for the user? For example, map users to folders on different drives.

from ftpserver.

fubar-coder avatar fubar-coder commented on August 20, 2024

The root path returned by IAccountDirectoryQuery might be relative to the file system root, but it might also be an absolute path, due to the way Path.Combine works.

from ftpserver.

aavanesov avatar aavanesov commented on August 20, 2024

For example, this set up will not change the drive to "C:" for the user, but will create a sub folders in D:\ drive like "d:\Temp\ftpserver\Temp\ftpserver":

services.Configure<DotNetFileSystemOptions>(opt =>  opt.RootPath = @"d:\Temp\ftpserver\");

// ...

public class FtpAccountDirectoryQuery : IAccountDirectoryQuery
{
    public IAccountDirectories GetDirectories(IAccountInformation accountInformation)
    {
        return new GenericAccountDirectories(@"c:\Temp\ftpserver\" + accountInformation.User.Name);
    }
}

from ftpserver.

fubar-coder avatar fubar-coder commented on August 20, 2024

Umm, no. The Users root directory will be c:\Temp\ftpserver\<username> and all directories he will create are in (or below) this directory, regardless of the DotNetFileSystemOptions configuration. BTW: You can differentiate between "normal" and "anonymous" FTP users by testing if accountInformation.User is of type IAnonymousFtpUser.

So, if your code returns new GenericAccountDirectories(null) for anonymous user, then those users will use d:\Temp\ftpserver, while authenticated users might be using c:\Temp\ftpserver\<username> as root directory.

from ftpserver.

Maciejszuchta avatar Maciejszuchta commented on August 20, 2024

I am wondering if this is correct configuration to use IAccountDirectoryQuery

 public class AccountDirectoryQuery : IAccountDirectoryQuery
    {
        private readonly IProjectsQueryHub _projectsQueryHub;
        private readonly IConfiguration _configuration;

        public AccountDirectoryQuery(IProjectsQueryHub projectsHub, IConfiguration configuration)
        {
            _projectsQueryHub = projectsHub;
            _configuration = configuration;
        }

        public IAccountDirectories GetDirectories(IAccountInformation accountInformation)
        {
            var adminUser = _configuration.GetSection("Settings")["FtpLogin"];
            var login = accountInformation.User.Name;
            var rootPath = _configuration.GetSection("Settings")["DataPath"];

            if (accountInformation.User.Name != adminUser)
            {
                var project = _projectsQueryHub.GetSingle(login).WaitResult();
                if (project != null)
                {

                    return new GenericAccountDirectories(Path.Combine("Upload", login));
                }
            }
            return new GenericAccountDirectories(rootPath);
        }
    }

and in startup:

services.Configure<DotNetFileSystemOptions>(opt =>
            {
                opt.RootPath = DataFolderPath;
            });

 services.AddFtpServer(builder => builder
                .UseDotNetFileSystem()
                .UseRootPerUser(opt => { opt.UserRootDirectory = "Upload"; })
            );

services.AddSingleton<IAccountDirectoryQuery, AccountDirectoryQuery>();

However, if I set a breakpoint in GetDirectories method it never hits. Also connecting with custom user name doesn't correctly set the root folder for this user.

I am really confused about how to configure the option so when the user is connecting its root directory is set to "Upload/userName" and when the Administrator connects root is set to a directory above Upload.

from ftpserver.

fubar-coder avatar fubar-coder commented on August 20, 2024

That the breakpoint doesn't get called means that services.AddSingleton<IAccountDirectoryQuery, AccountDirectoryQuery>(); gets executed before the services.AddFtpServer line. The UseRootPerUser adds its own IAccountDirectoryQuery implementation to the service collection.

from ftpserver.

Maciejszuchta avatar Maciejszuchta commented on August 20, 2024

@fubar-coder Thank you,
After changing the order and some fixes here and there it started working as expected.

from ftpserver.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.