You can't do that out of the box, but once the SftpSubsystem is created, you
should be able to customize the root by overriding the start() method and
find the user name in the session using session.getUsername().
Not sure if we can really come up with something generic, but we could at
least provide a method that could be easily overriden if there is a need.
So maybe something like:
public class MySftpSubsystem extends SftpSubsystem {
public static class Factory implements NamedFactory<Command> {
public Command create() {
return new MySftpSubsystem();
}
public String getName() {
return "sftp";
}
}
public MySftpSubsystem() {
super(new File(".");
}
public void start(Environment env) throws IOException {
String username = session.getUsername();
this.root = getRoot(username);
super.start();
}
protected File getRoot(String username) {
// put your logic here
}
}
On Sat, May 29, 2010 at 01:36, Toli Kuznets <[email protected]>wrote:
> Hi,
>
> I'm trying to see if i can use the SSHD project to create an "SFTP"
> server that will allow users to log in, and serve up a different
> directory for each user.
>
> The FtpServer project allows you to create a virtual FS for each user,
> and i'm hoping to be able to do the same for SFTP connections with
> SSHD project.
>
> Is there a way to implement that?
>
> Currently, it seems that the SftpSubsystem is being created by a
> factory that is created before a user logs in.
> Seems that by the time code path gets to the SftpSubsystemFactory, the
> username of the user coming in is lost and doesn't come through to the
> factory creating the SftpSubsystem.
>
> Is there a way to pass the username in so that a different directory
> can be served up to the user when the "log on"?
>
> thanks
>
> ps: thanks for the great project.
>
--
Cheers,
Guillaume Nodet
------------------------
Blog: http://gnodet.blogspot.com/
------------------------
Open Source SOA
http://fusesource.com