Skip to content

Instantly share code, notes, and snippets.

@alces
Created July 5, 2016 06:12
Show Gist options
  • Save alces/599b1bbe53b33ddbad5f32aa553e2aea to your computer and use it in GitHub Desktop.
Save alces/599b1bbe53b33ddbad5f32aa553e2aea to your computer and use it in GitHub Desktop.
The script demonstrates using Ant scp and sshexec tasks from Groovy
@GrabConfig(systemClassLoader = true)
@Grab('jsch:jsch')
@Grab('ant:ant-jsch')
def sshHost = '127.0.0.1'
def sshPort = 2200
def sshUser = 'vagrant'
def sshPrivKey = "${System.getProperty('user.home')}/.vagrant.d/insecure_private_key"
def ant = new AntBuilder()
ant.sshexec(host: sshHost,
port: sshPort,
username: sshUser,
keyfile: sshPrivKey,
command: 'ls -l /')
ant.scp(file: '/etc/services',
todir: "${sshUser}@${sshHost}:/home/vagrant",
port: sshPort,
keyfile: sshPrivKey,
passphrase: '')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment