Created
December 31, 2014 15:56
-
-
Save aaronhanson/f5e268ae4718bcf760ca to your computer and use it in GitHub Desktop.
Simple Groovy Sftp Server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Grab(group='org.apache.sshd', module='sshd-core', version='0.13.0') | |
import org.apache.sshd.SshServer | |
import org.apache.sshd.server.PasswordAuthenticator | |
import org.apache.sshd.server.command.ScpCommandFactory | |
import org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider | |
import org.apache.sshd.server.session.ServerSession | |
import org.apache.sshd.server.sftp.SftpSubsystem | |
import org.apache.sshd.server.shell.ProcessShellFactory | |
int sftpPort = 2200 | |
SshServer sshd = SshServer.setUpDefaultServer() | |
sshd.setPort(sftpPort) | |
sshd.setKeyPairProvider(new SimpleGeneratorHostKeyProvider("hostkey.ser")) | |
sshd.setPasswordAuthenticator( | |
[ | |
authenticate: { String username, String password, ServerSession session -> | |
return username.equals('anonymous') || (username && username.equals(password)) | |
} | |
] as PasswordAuthenticator | |
) | |
sshd.setShellFactory(new ProcessShellFactory(["/bin/sh", "-i", "-l"] as String[])) | |
sshd.setSubsystemFactories([new SftpSubsystem.Factory()]) | |
sshd.setCommandFactory(new ScpCommandFactory()) | |
sshd.start() | |
println "listening..." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment