Ant Copy Command-SCP


Ant is a platform-independent scripting tool that lets you construct your build scripts in much the same fashion as the "make" tool in C or C++. You can use a large number of built-in tasks in Ant without any customization. 
Copies a file or FileSet to or from a (remote) machine running an SSH daemon. FileSet only works for copying files from the local machine to a remote machine.

Examples

Copy a single local file to a remote machine

<scp file=”myfile.txt” todir=”user:password@somehost:/home/chuck”/>

Copy a single local file to a remote machine with separate password attribute

<scp file=”myfile.txt” todir=”user@somehost:/home/chuck” password=”password”/>

Copy a single local file to a remote machine using key base authentication.

<scp file=”myfile.txt”

todir=”user@somehost:/home/chuck”

keyfile=”${user.home}/.ssh/id_dsa”

passphrase=”my extremely secret passphrase”

/>

Copy a single remote file to a local directory

<scp file=”user:password@somehost:/home/chuck/myfile.txt” todir=”../some/other/dir”/>

Copy a remote directory to a local directory

<scp file=”user:password@somehost:/home/chuck/*” todir=”/home/sara”/>

Copy a local directory to a remote directory

<scp todir=”user:password@somehost:/home/chuck/”>

<fileset dir=”src_dir”/>

</scp>

Copy a set of files to a directory

<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>

Security Note: Hard coding passwords and/or usernames in scp task can be a serious security hole. Consider using variable substitution and include the password on the command line. For example:

<scp todir=”${username}:${password}@host:/dir” …>

Invoking ant with the following command line:

ant -Dusername=me -Dpassword=mypassword target1 target2

Is slightly better, but the username/password is exposed to all users on an Unix system (via the ps command). The best approach is to use the <input> task and/or retrieve the password from a (secured) .properties file.

Unix Note: File permissions are not retained when files are copied; they end up with the default UMASK permissions instead. This is caused by the lack of any means to query or set file permissions in the current Java runtimes. If you need a permission- preserving copy function, use <exec executable=”scp” … > instead.

To know more click here

0 comments:

Post a Comment