ant scp 端口_用Ant将文件copy到远程服务器

开发时,常常需要将文件copy到远程服务器,以前都是手工copy:打开scp客户端,连接上远程服务器,然后将本地文件一个一个或者一批一批的拖到远程服务器上。

这样做太麻烦,所以用ant.

可是一般ant只是用来将本地文件拷来拷去,像下面这样:

能不能将文件copy到远程呢?

能,用scpcopy,像这样

这样你就不用手工copy了,只需要运行 ant 命令就行了。

但你可能会碰到这个问题:

D:\workspace\websocket_server\signalserver>ant scpcopy

Buildfile: D:\workspace\websocket_server\signalserver\build.xml

scpcopy:

BUILD FAILED

D:\workspace\websocket_server\signalserver\build.xml:15: Problem: failed to create task or type scp

Cause: Could not load a dependent class com/jcraft/jsch/Logger

It is not enough to have Ant's optional JARs

you need the JAR files that the optional tasks depend upon.

Ant's optional task dependencies are listed in the manual.

Action: Determine what extra JAR files are needed, and place them in one of:

-C:\apache-ant-1.9.6\lib

-C:\Users\qingjieh\.ant\lib

-a directory added on the command line with the -lib argument

Do not panic, this is a common problem.

The commonest cause is a missing JAR.

This is not a bug; it is a configuration problem

Total time: 0 seconds

这是因为你没有将jsch-0.1.55.jar 下载下来放到到C:\apache-ant-1.9.6\lib\里

接着你又可能会碰到这个问题:

D:\workspace\websocket_server\signalserver\build.xml:15: com.jcraft.jsch.JSchException: reject HostKey: 10.133.185.82

at com.jcraft.jsch.Session.checkHost(Session.java:799)

at com.jcraft.jsch.Session.connect(Session.java:345)

at com.jcraft.jsch.Session.connect(Session.java:183)

at org.apache.tools.ant.taskdefs.optional.ssh.SSHBase.openSession(SSHBase.java:225)

at org.apache.tools.ant.taskdefs.optional.ssh.Scp.upload(Scp.java:348)

at org.apache.tools.ant.taskdefs.optional.ssh.Scp.execute(Scp.java:244)

at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:293)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at java.lang.reflect.Method.invoke(Method.java:497)

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:435)

at org.apache.tools.ant.Target.performTasks(Target.java:456)

at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1405)

at org.apache.tools.ant.Project.executeTarget(Project.java:1376)

at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)

at org.apache.tools.ant.Project.executeTargets(Project.java:1260)

at org.apache.tools.ant.Main.runBuild(Main.java:853)

at org.apache.tools.ant.Main.startAnt(Main.java:235)

at org.apache.tools.ant.launch.Launcher.run(Launcher.java:285)

at org.apache.tools.ant.launch.Launcher.main(Launcher.java:112)

Total time: 0 seconds

那是因为你没有设置trust="true",咱们给它加上。

运行,一切OK.

D:\workspace\websocket_server\signalserver>ant scpcopy

Buildfile: D:\workspace\websocket_server\signalserver\build.xml

scpcopy:

[scp] Connecting to 192.168.0.99:22

[scp] done.

BUILD SUCCESSFUL

Total time: 1 second

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值