Open mertpp opened 2 days ago
Yeah - this might be tricky at the moment, as both the server_factory
and sftp_factory
arguments right now only support callables, and don't allow awaitables.
One thing you might try is setting an acceptor
on the call to create_server()
. That can be an awaitable, and receives an SSHServerConnection as an argument. You can get the username from that connection object via get_extra_info()
, similar to what the current example does using chan.get_extra_info()
, do your database lookup, and then store the directory information back into the SSHServerConnection with set_extra_info()
. Later, in the SFTP initialization, you'd just query for the directory via chan.get_extra_info()
instead of querying for the username.
A cleaner fix would be to add the ability in AsyncSSH to use awaitables for more of the factory calls, and I've been doing that a little at a time (most recently to auth and kex exchange calls), but that has its own challenges, and can introduce race conditions if not done very carefully.
As an aside, I also noticed you are setting process_factory
here, but I don't believe that should be necessary. AsyncSSH should automatically block shell/exec requests when process_factory
and session_factory
are not set, unless you allow it via custom callbacks in an SSHServer class. Passing in a lambda which takes no arguments might even break things, as a process factory is supposed to take an SSHServerProcess argument when it is called.
Hello I need to get the path of the chroot of the user from the database. This is how I use my sftp server to create server.
This is how I implemented sftp server. the problem is at the get account by username method. That method should be asynchronous. I couldn't make init method asynchronous.
Copilot suggested me to create a create factory method that returns the instance of mysftpserver. But in that case the code block above doesn't work.
How can I change chroot of the sftp user retrieved from the database during the initialization?
I see ssh classes has
connection_made
method but SFTP subclasses doesn't, so I cannot change the users chroot after initialization.thank you for your help.