2013-10-24 60 views
0

我用java/Groovy中這樣如何控制下載過程在Linux

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

如何控制或已知當文件完成下載或錯誤發生,並下載文件到遠程文件通過ssh迴應過程?

回答

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