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.

BlueSun
  • 3,541
  • 1
  • 18
  • 37
AcidHawk
  • 496
  • 7
  • 18

2 Answers2

12

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

sftpServer.setSubsystemFactories(
    Arrays.<NamedFactory<Command>>asList(new SftpSubsystemFactory()));
Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
  • 1
    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. – AcidHawk May 08 '17 at 09:21
  • 1
    Thanks, that worked for me. All the examples on the internet had SftpSubsystem.Factory . Ugh. – djangofan May 12 '18 at 00:14
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()));
Krishna
  • 33
  • 5