Home » Java » Apache Mina SFTP SftpSubsystem.Factory()

Apache Mina SFTP SftpSubsystem.Factory()

Posted by: admin December 28, 2021 Leave a comment


I am trying to setup a simple SFTP server using Apache Mine SSHD v1.2.0.

I have looked at several examples on the web E.g. here, here and here.

However they all have the same line in common which I cannot get NetBeans to resolve. NetBeans tells me that it cannot find Factory in SftpSubsystem. The line in question looks as follows:

sftpServer.setSubsystemFactories (
    Arrays. <NamedFactory <Command >> asList (new SftpSubsystem.Factory ()));

My main looks something like the following:

SshServer sftpServer = SshServer.setUpDefaultServer ();
sftpServer.setPort (PORT);
sftpServer.setKeyPairProvider (new SimpleGeneratorHostKeyProvider (new File("hostkey.ser")));
sftpServer.setSubsystemFactories (
     Arrays. <NamedFactory <Command >> asList (new SftpSubsystem.Factory ()));
sftpServer.setPasswordAuthenticator (new PasswordAuthenticator () {
    public boolean authenticate (String username, String password, ServerSession session) {
       return true;
sftpServer.start ();

What am I missing? I simply want to connect to a dummy SFTP server and list some directories and upload a file or two. The thing is that I want to do this from inside an existing java application.


In recent versions of Apache SSHD, it’s SftpSubsystemFactory:

    Arrays.<NamedFactory<Command>>asList(new SftpSubsystemFactory()));


I’m using version 2.6.0, and now you don’t need to typecast. You can simply say:

sftpServer.setSubsystemFactories(Arrays.asList(new SftpSubsystemFactory()));