简体   繁体   中英

Apache Mina SFTP SftpSubsystem.Factory()

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 Eg 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.

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

sftpServer.setSubsystemFactories(
    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()));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM