ANT中的SSHEXEC和SCP任务用法

来源:互联网 发布:分析软件 编辑:程序博客网 时间:2024/06/06 09:32

ANT中的SSHEXEC和SCP任务

本文通过简单示例介绍如何利用ant的sshexec和scp执行ssh和scp命令的方法。

1 安装依赖jar包

从JCRAFT上下载最新的jsch-*.jar。我下载的是jsch-0.1.53.jar。
将该jar文件拷贝到$ANT_HOME/lib/下,即ant主目录下的lib/目录下。

2 SSHEXEC示例

代码:
exec.xml

<?xml version="1.0" encoding="UTF-8"?><project default="touch_somefile">    <target name="touch_somefile">        <sshexec host="localhost"           username="${username}"           password="${password}"           command="touch /tmp/somefile2"           trust="true"/>    </target></project>

代码中的trust=”true”相当与ssh的 -o “StrictHostKeyChecking no“选项。
执行命令:

ant -Dusername=test -Dpassword=1234 -f exec.xml

3 SCP示例

核心代码:

<scp todir="${username}:${password}@somehost:/home/chuck">  <fileset dir="src_dir">    <include name="**/*.java"/>  </fileset></scp><scp todir="${username}:${password}@somehost:/home/chuck">  <fileset dir="src_dir" excludes="**/*.java"/></scp>
1 0
原创粉丝点击