Java 如何在linux中控制下载过程
我必须像这样使用java/groovy通过ssh将文件下载到远程文件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
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' )