使用ant将文件从Windows上传至Linux

ant支持将文件从本地上传到Linux下,具体代码(亲测):
<?xml version="1.0" ?>
<project name="upload" default="scp-file">
<target name="scp-file">  
    <scp file="output/SSU.tar.gz" todir="test:test@10.10.96.160:/home/myuser/install" trust="true"/> 
</target>  
</project>
当前在上传之前,需要从http://www.jcraft.com/jsch/index.html 下载jsch,jar到ant的lib目录下,以支持scp功能
进行目标文件通配可以采用include,如下,将*.tar.gz上传
<?xml version="1.0" ?>
<project name="upload" default="scp-file">
<target name="scp-file">  
    <scp todir="test:test@10.10.96.160:/home/myuser/install" trust="true">
  <fileset dir="output" includes="*.tar.gz"/>
</scp> 
</target>  
</project>
一定要加trust=true,代表信任主机,否则在本地的knowhosts必须存在目标远程IP。
附:

[scp任务]

参考:http://jiajun.iteye.com/blog/741001

         http://www.imooo.com/linux/linux-unix/523844.htm

1.拷贝单个文件到远端服务器
<scp file="c:/cmd.txt" todir="root:123456@192.168.122.180:/tmp" trust="true"/>

<scp file="c:/cmd.txt" todir="root@192.168.122.180:/tmp" password="123456" trust="true"/>

2.拷贝远端文件本地
<scp file="root:123456@192.168.122.180:/tmp/cmd.txt" todir="D:/my-app"  trust="true"/>

3.拷贝远端目录到本地,将以递归形式操作
<scp file="root:123456@192.168.122.180:/tmp/*" todir="d:/my-app" trust="true"/>

4.拷贝本地目录中的内容到远端,递归形式,但不在服务器上建立my-app目录
<scp todir="root:123456@192.168.122.180:/tmp/" trust="true">
   
<fileset dir="d:/my-app"/>
</scp>

5.拷贝一系列的文件到远端,会建立相应的层次目录,不建立my-app目录
<scp todir="root:123456@192.168.122.180:/tmp" trust="true">
   
<fileset dir="d:/my-app">
      
<include name="**/*.java" />
   
</fileset>
</scp>

<scp todir="root:123456@192.168.122.180:/tmp" trust="true">
   
<fileset dir="d:/my-app" excludes="**/*.java"/>
</scp>

最后一个任务的执行输出结果如下(其他略):

scp:
      [scp]Connecting to 192.168.122.180:22
      [
scp] Sending: cmd.txt : 0
      [
scp] File transfer time: 0.0 Average Rate: ? B/s
      [
scp] Sending: pom.xml : 852
      [
scp] File transfer time: 0.0 Average Rate: ∞ B/s
      [
scp] Sending: application.properties : 142
      [
scp] File transfer time: 0.0 Average Rate: ∞ B/s
      [
scp] Sending: application.properties : 45
      [
scp] File transfer time: 0.0 Average Rate: ∞ B/s
      [
scp] Sending: test.properties : 0
      [
scp] File transfer time: 0.02 Average Rate: 0.0 B/s
      [
scp] Sending: application.properties : 153
      [
scp] File transfer time: 0.0 Average Rate: ∞ B/s
      [
scp] Sending: application.properties : 45
      [
scp] File transfer time: 0.0 Average Rate: ∞ B/s
      [
scp] done.

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值