Skip to content

Instantly share code, notes, and snippets.

@Riggs333
Forked from chilicat/scp-ssh.gradle
Last active August 29, 2015 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Riggs333/0fcacdddd90d65e7a992 to your computer and use it in GitHub Desktop.
Save Riggs333/0fcacdddd90d65e7a992 to your computer and use it in GitHub Desktop.
repositories { mavenCentral() }
configurations { sshAntTask }
dependencies { sshAntTask 'org.apache.ant:ant-jsch:1.9.2' }
ant.taskdef(
name: 'scp',
classname: 'org.apache.tools.ant.taskdefs.optional.ssh.Scp',
classpath: configurations.sshAntTask.asPath)
ant.taskdef(
name: 'ssh',
classname: 'org.apache.tools.ant.taskdefs.optional.ssh.SSHExec',
classpath: configurations.sshAntTask.asPath)
task scpAndScpTest() << {
// Create a new file for each execution to make
// sure that execution doesn't fails in case
// idententy of host has been changed.
def knownHosts = File.createTempFile("knownhosts", "txt")
def user = 'root'
def host = '10.129.184.44'
def privateKey = file('keys/myKey')
try {
// Example to copy files to a remote host.
ant.scp(
file: file("build.gradle"),
todir: "${user}@${host}:~",
keyfile: privateKey,
trust: true,
knownhosts: knownHosts
)
// Example to execute a command on the remote host.
ant.ssh(
host: host,
username: user,
keyfile: privateKey,
trust: true,
knownhosts: knownHosts,
command: "ls /"
)
} finally {
knownHosts.delete()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment