Ant: copying a directory from one windows system to another

17,258

Solution 1

Download:

<scp file="${username}:${password}@${ip}:${path-to-file}" todir="${dir}" trust="true" />

or Upload:

<scp file="${path-to-file}" todir="${username}:${password}@${ip}:${dir}" trust="true" />  

Ant scp task provides attributes such as localFile and remoteFile to replace "file", and localTofile / localTodir and remoteTofile / remoteTodir to replace "dir". Using these attributes can help avoid confusion when you need some scp tasks to get files from the server to local machine, while others to upload files from the local machine to server.
Like this (for uploading):

<scp localFile="${path-to-file}" remoteTodir="${username}:${password}@${ip}:${dir}" trust="true" />

Check the ant manual to see more information: http://ant.apache.org/manual/Tasks/scp.html

Note:
1. Avoid copying multiple files; Copy a zip archive and a ant build file together with it, and unzip on target machine.
2. Using scp, you need to setup ssh server on the target machine; you also need to put jsch.jar in your ANT_HOME/lib. The jsch.jar can be downloaded from

http://www.jcraft.com/jsch/index.html

Solution 2

You should go for using FTP to copy files between the windows machines. There are other protocal too, but you should go with FTP.

A sample for using FTP.

<ftp server="${server.location}"
   remotedir="${directory.to.copy}"
   userid="${ftp.username}"
   password="${ftp.password}"
   depends="yes">
   <fileset dir="**Files****"/>
</ftp>

You can further look for details here. There are many options to try there.

Solution 3

First you download jsch-0.1.53.jar file from http://www.jcraft.com/jsch/ in your C:\apache-ant-1.8.2\lib folder. Then have below line of code in your build.xml

<scp file="${userName}:${password}@${${ip_address}:${directory}/${FileName}" todir="${localDir_Where_to _Copy}" trust="true" />

Then have above line of code in your build.xml

Share:
17,258
Abhinav Garg
Author by

Abhinav Garg

Updated on June 04, 2022

Comments

  • Abhinav Garg
    Abhinav Garg almost 2 years

    How to copy a directory from a windows system to a remote windows system using ant

    there is one scp command and FTP command, please provide me an example to perform this task using scp and ftp.

    Also scp requires SSH which is not common for windows system.

    So how to use SCP on windows system using ant

    Also if you know any better approach for windows system using ant or java, please share

    Also there is one SC command(don't know how to use it)