Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/28.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何在linux中控制下载过程_Java_Linux_Groovy_Wget - Fatal编程技术网

Java 如何在linux中控制下载过程

Java 如何在linux中控制下载过程,java,linux,groovy,wget,Java,Linux,Groovy,Wget,我必须像这样使用java/groovy通过ssh将文件下载到远程文件 process = "ssh 113.114.115.116 sudo wget http://webserver.com/file.zip".execute() 如何控制或知道文件下载完成或错误发生以及对进程的响应?您可以尝试以下方法: @GrabConfig(systemClassLoader=true) @Grab( 'org.apache.ant:ant-jsch:1.9.2' ) @Grab( 'com.jcraf

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

process = "ssh 113.114.115.116 sudo wget http://webserver.com/file.zip".execute()
如何控制或知道文件下载完成或错误发生以及对进程的响应?

您可以尝试以下方法:

@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' )