Add SFTP support (#7)

Add SFTP support
This commit is contained in:
Tony 2018-03-25 13:44:41 -06:00 committed by Roman Zabaluev
parent 16f5c063ce
commit 69d31175d4
2 changed files with 18 additions and 0 deletions

View File

@ -1,11 +1,15 @@
package com.ryanmichela.sshd; package com.ryanmichela.sshd;
import org.apache.sshd.common.file.virtualfs.VirtualFileSystemFactory;
import org.apache.sshd.server.SshServer; import org.apache.sshd.server.SshServer;
import org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider; import org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider;
import org.apache.sshd.server.subsystem.sftp.SftpSubsystemFactory;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.nio.file.FileSystems;
import java.util.Collections;
import java.util.logging.Level; import java.util.logging.Level;
/** /**
@ -45,6 +49,16 @@ public class SshdPlugin extends JavaPlugin {
sshd.setShellFactory(new ConsoleShellFactory()); sshd.setShellFactory(new ConsoleShellFactory());
sshd.setPasswordAuthenticator(new ConfigPasswordAuthenticator()); sshd.setPasswordAuthenticator(new ConfigPasswordAuthenticator());
sshd.setPublickeyAuthenticator(new PublicKeyAuthenticator(authorizedKeys)); sshd.setPublickeyAuthenticator(new PublicKeyAuthenticator(authorizedKeys));
if (getConfig().getBoolean("enableSFTP")) {
sshd.setSubsystemFactories(Collections.singletonList(new SftpSubsystemFactory()));
sshd.setFileSystemFactory(new VirtualFileSystemFactory(
FileSystems.getDefault().getPath(
getDataFolder().getAbsolutePath()
).getParent().getParent()
));
}
sshd.setCommandFactory(new ConsoleCommandFactory()); sshd.setCommandFactory(new ConsoleCommandFactory());
try { try {
sshd.start(); sshd.start();

View File

@ -7,6 +7,10 @@ port: 22
# Operational mode. Don't touch if you don't know what you're doing. Can be either DEFAULT or RPC # Operational mode. Don't touch if you don't know what you're doing. Can be either DEFAULT or RPC
mode: DEFAULT mode: DEFAULT
# Enable built-in SFTP server or not. You'll be able to connect and upload/download files via SFTP protocol.
# Might be useful for testing purposes as well , i. e. docker containers.
enableSFTP: true
# By default, only public key authentication is enabled. This is the most secure mode. # By default, only public key authentication is enabled. This is the most secure mode.
# To authorize a user to log in with public key authentication, install their public # To authorize a user to log in with public key authentication, install their public
# PEM certificate in the authorized_users directory. Name the key file with user's user # PEM certificate in the authorized_users directory. Name the key file with user's user