Skip to content

Instantly share code, notes, and snippets.

@aaronhanson
Created December 31, 2014 15:56
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aaronhanson/f5e268ae4718bcf760ca to your computer and use it in GitHub Desktop.
Save aaronhanson/f5e268ae4718bcf760ca to your computer and use it in GitHub Desktop.
Simple Groovy Sftp Server
@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