0

I have to download a file to remote file via ssh using java/groovy like this

process = "ssh 113.114.115.116 sudo wget http://webserver.com/file.zip".execute()

how can i control or known when file is complete downloaded or error occurrence and response to process ?

1 Answer 1

0

You could try this:

@GrabConfig(systemClassLoader=true)
@Grab( 'org.apache.ant:ant-jsch:1.9.2' )
@Grab( 'com.jcraft:jsch:0.1.50' )

def doExec( host, uid, pwd, cmd ) {
    new AntBuilder().with {
        // Turn off logging
        project.buildListeners.firstElement().messageOutputLevel = 0

        // Execute command
        sshexec( host           : host,
                 username       : uid, 
                 password       : pwd,
                 command        : cmd,
                 outputproperty : 'result' )

        // Return output         
        project.properties.result
    }
}

println doExec( '113.114.115.116',
                'USERNAME',
                'PASSWORD',
                'sudo wget http://webserver.com/file.zip' )

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.