Comments (8)
Implement IAccountDirectoryQuery
and add it as "singleton" service.
from ftpserver.
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.
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.
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.
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.
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.
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.
@fubar-coder Thank you,
After changing the order and some fixes here and there it started working as expected.
from ftpserver.
Related Issues (20)
- UseImplicitTls throws error
- IFTPServer.Status Never Resets HOT 1
- Strange Filezilla behavior HOT 1
- Docker container PASV not able to connect HOT 4
- How to reject non-encrypted connections when I use the TLS function? HOT 2
- Cant stop the Server HOT 2
- LANG catalog loader - unnecessary NGettext dependency and debug log messages HOT 2
- ServerCertificate HOT 2
- BUG: FtpConnection.cs HOT 1
- FtpServerBuilderExtensionsForChecks.cs IFtpConnectionCheck HOT 1
- Memory leak because of Task.Delay(-1, token) HOT 3
- Bug inactivity timeout HOT 1
- Configure multiple command ports HOT 3
- Abnormal operation of DEMO program HOT 1
- How to make a directory read only
- Event/Trigger in server code when a new file was created by client
- Missing logger in XrmdCommandHandler and RmdCommandHandler
- A simple help wouldn't be bad at all friends 💥 HOT 1
- Disconnects from server every 60 seconds when using FTP and FTPS HOT 2
- InMemoryFileSystem documentation HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ftpserver.