0
我對這個主題Apache Ant很陌生,我想使用ant sshexec任務在遠程計算機上運行命令。這是我大學畢業論文的一部分。我必須儘快解決這個問題。有這樣一個目標:使用ant sshexec任務在遠程計算機上運行命令
<target id="9" name="connectrun">
<sshexec host="192.168.1.34"
username="remoteusername"
password="remotepassword"
trust="true"
verbose="true"
command="cmd /c dir C:\">
</sshexec>
</target>
我使用ant版本1.8.2和jsch-0.1.48.jar。操作系統是每臺計算機的Windows 7。我關掉窗口防火牆當我運行的目標,我想借此錯誤:
Caused by: java.net.ConnectException: Connection refused: connect
這是一個通用的Java網絡錯誤,拋出時,它的:在Java堆棧跟蹤仔細
com.jcraft.jsch.JSchException: java.net.ConnectException: Connection refused: connect
at com.jcraft.jsch.Util.createSocket(Util.java:341)
at com.jcraft.jsch.Session.connect(Session.java:182)
at com.jcraft.jsch.Session.connect(Session.java:150)
at org.apache.tools.ant.taskdefs.optional.ssh.SSHBase.openSession(SSHBase.java:223)
at org.apache.tools.ant.taskdefs.optional.ssh.SSHExec.execute(SSHExec.java:190)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
at org.apache.tools.ant.Task.perform(Task.java:348)
at org.apache.tools.ant.Target.execute(Target.java:390)
at org.apache.tools.ant.Target.performTasks(Target.java:411)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399)
at org.apache.tools.ant.Project.executeTarget(Project.java:1368)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
at org.apache.tools.ant.Project.executeTargets(Project.java:1251)
at org.apache.tools.ant.module.bridge.impl.BridgeImpl.run(BridgeImpl.java:284)
at org.apache.tools.ant.module.run.TargetExecutor.run(TargetExecutor.java:539)
at org.netbeans.core.execution.RunClassThread.run(RunClassThread.java:153)
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.DualStackPlainSocketImpl.connect0(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:69)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:157)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:391)
at java.net.Socket.connect(Socket.java:579)
at java.net.Socket.connect(Socket.java:528)
at java.net.Socket.<init>(Socket.java:425)
at java.net.Socket.<init>(Socket.java:208)
at com.jcraft.jsch.Util.createSocket(Util.java:335)
你有沒有在你試圖連接的機器上運行ssh服務器?嘗試使用putty或其他ssh客戶端建立一個ssh連接並讓它工作。 – krock
我已經在我的遠程Windows服務器上安裝了freeSSHd服務器。我已將SSH偵聽端口設置爲22,此端口是默認端口,當然您可以更改。對於其他想要爲此主題提供幫助的人: http://www.techmalaya.com/2009/08/05/setup-ssh-server-for-windows-freesshd/ 不要忘記我們將使用用戶名和由SSH服務器創建的密碼。小心不要使用Windows用戶名。謝謝。 – recepbostanci