开发者

Ant: copying a directory from one windows system to another

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

Als开发者_JAVA技巧o there is one SC command(don't know how to use it)


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


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.


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


To copy a directory from your local host to a remote host using the ant scp, you have to specify the parent of the directory to the fileset and include the directory name eg.

<scp todir="user@hostname:/destination/dir/" keyfile="id_dsa" passphrase="abc" sftp="true" >
    <fileset dir="${parentDir}/"  >
        <include name="**/${dirToCopy}/" />
    </fileset>
</scp> 

sftp="true" helped another user on this subject so I included it. In my case I believe that adding the "/" at the end of the parentDir and dirToCopy, which signifies a directory at the command line, finally let me copy a directory and not just it's contents.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜