0

我必须像这样使用 java/groovy 通过 ssh 将文件下载到远程文件

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

我如何控制或知道文件何时完成下载或错误发生和对过程的响应?

4

1 回答 1

0

你可以试试这个:

@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' )
于 2013-10-24T08:26:16.860 回答