如何在linux中控制下载过程

时间:2013-10-24 02:29:36

标签: java linux groovy wget

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

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

如何控制或知道文件何时完整下载或错误发生以及对流程的响应?

1 个答案:

答案 0 :(得分: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' )