Apache Mina SFTP SftpSubsystem.Factory()
Asked Answered
P

2

7

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 () {
    @Override
    public boolean authenticate (String username, String password, ServerSession session) {
       return true;
    }
});
sftpServer.start ();
while(true);

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.

Pulchritudinous answered 8/5, 2017 at 8:22 Comment(0)
E
12

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

sftpServer.setSubsystemFactories(
    Arrays.<NamedFactory<Command>>asList(new SftpSubsystemFactory()));
Exclosure answered 8/5, 2017 at 8:59 Comment(2)
Thank you. I am not sure why I couldn't find that but replacing my line with the one you provided sorted my problem out.Pulchritudinous
Thanks, that worked for me. All the examples on the internet had SftpSubsystem.Factory . Ugh.Chaisson
R
3

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()));
Reareace answered 23/5, 2021 at 10:49 Comment(1)
You can also use "Collections.singletonList" instead.Reareace

© 2022 - 2024 — McMap. All rights reserved.