使用ant scp传输文件

由于项目有多台服务器,每次增量更新时太烦了,就想用程序更新,使用ftp和ant都试过了,都可以.

ftp经常使用没有问题,ant第一次自己写出了不少问题.我使用的是win7.特此记录.


<project name="ServerStatusChecker" basedir="." default="scpUpload"> 

<!-- 下面这个文件夹无效 -->
<target name="scpUpload1" description="Upload TestWebEAR.ear to server"> 
<scp file="d:/antTest/runtime" todir="administrator:123456@127.0.0.1:" trust="true" /> 
</target>

<!-- 上面这个文件夹无效 -->
<target name="scpUpload" description="Upload TestWebEAR.ear to server">
<scp todir="administrator:123456@127.0.0.1:D:\\ftpSharedFold\\upload" trust="true">
<fileset dir="runtime"><!--<include name="**/*.properties"/>-->
</fileset></scp>
</target>
<record name="D:/antTest/log4j.log" loglevel="info" append="no" action="start"/>
</project>

1、D:\antTest\build.xml:22: com.jcraft.jsch.JSchException: java.net.ConnectException: Connection refused: connect
在http://lilinhui.iteye.com/blog/1150559这篇文章找到答案,注册ssh服务
2、没有弄清楚文件目录的关系。basedir=".",当todir="administrator:123456@127.0.0.1:" 时,会将runtime目录下的文件
复制到C:\Users\Administrator文件夹中,runtime文件夹名称不会移动到对面。目标路径也可以写绝对路径,但是要写已经存在的路径,
否则会报D:\antTest\build.xml:10: server indicated an error: scp: D:\\ftpSharedFold\\upload1: Not a directory.
还不清楚这个是不是我没弄清楚。
当上传单个文件时,todir中的地址可以写一个文件名,也可以写一个已经存在文件夹
例如todir="administrator:123456@127.0.0.1:workspace/",workspace文件夹就存在
3、scp标签的写法。写成这样的时候<scp file="d:/antTest/runtime" todir="administrator:123456@127.0.0.1:" trust="true" />
可以上传单个文件,但是文件夹不行,会报D:\antTest\build.xml:6: java.io.FileNotFoundException: d:\antTest\runtime (拒绝访问。)
只能用fileset 标签,但是网上说可以用上面的写法,难道是版本问题,我的ant版本是1.10.1。
还好在这个找到了正确的写法http://grokbase.com/t/ant/user/074bs5hqsw/help-how-to-send-multiple-files-to-remote-machine-ant-jsch。

<scp todir="user:password@somehost:/home/chuck">
<fileset dir="src_dir">
<include name="**/*.java"/>
</fileset>
</scp>
<scp todir="user:password@somehost:/home/chuck">
<fileset dir="src_dir" excludes="**/*.java"/>
</scp>



  
  







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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值