0

As I've readen ant doesn't provide 'fileset' attribute when downloading files from remote machine via scp task. It works when sending files from local machine, but It doesn't work when starting in remote machine. That's from documentation. So in remote machine I have some folders and load of files in every directory. I want to download all folders and one specified file from every of them. Downloading all files and then deleting unneeded files won't be solution beacuse there are thousands of files.

So. How to download all folders (only create the on disk without content) from specified directory in remote machine and then download one specified file from every directory in remote machine and put it to corresponding folder using ant?

1 Answers1

1

Since you haven't specified I'll assume that your local and remote systems are unix based and therefore support rsync and ssh.

A more cross-platform solution is challenging...

Example

Configure SSH

Generate an SSH key (specify an empty passphrase):

ssh-keygen -f rsync

This will generate 2 files, corresponding to the private and public keys:

|-- rsync
`-- rsync.pub

Install the public key on the remote server

ssh-copy-id -i rsync.pub user@remote

Test that you can now perform a password-less login, using the ssh private key to authenticate:

ssh -i rsync user@remote

ANT

The "download" target invokes rsync to copy the remote file system tree locally. If required one can additionally specify rsync exclusions (see the rsync doco).

<project name="rsync" default="download">

    <target name="download">
        <exec executable="rsync">
            <arg line="-avz -e 'ssh -i rsync' user@remote:/path/to/data/ data"/>
        </exec>
    </target>

    <target name="clean">
        <delete dir="data"/>
    </target>

</project>
Mark O'Connor
  • 76,015
  • 10
  • 139
  • 185
  • So for example I have filesystem: dir1 ---file ---other dir2 ---file ---other dir3 ---file ---other dir4 ---file ---other dir5 ---file ---other And I want ant to download and create on my disk every dir* and download only 'file' to every dir will it work? And second thing. My topic http://stackoverflow.com/questions/12192339/ant-get-directiores-names-from-remote-machine IS NOT a duplicate. Topic under link is about getting folders names and save it for example in text file. Something like ls > temp.txt. Nothing to download... (I've received ban to ask questions, maybe beacues of it mainly.) – user15683854875644328975643872 Sep 05 '12 at 07:51
  • Soooo.. in my case I didn't need to do anything with keys, I just invoked ssh task with trust property set to true and it worked. Greets. – user15683854875644328975643872 Sep 05 '12 at 13:49
  • @user15683854875644328975643872 The trust="true" attribute on the ANT ssh task has nothing to do with authentication. I suspect you additionally specified "username" and "password" attributes. – Mark O'Connor Sep 05 '12 at 23:35
  • username and password is basic thing. Adding trust attribute was additional. – user15683854875644328975643872 Sep 06 '12 at 07:39
  • @user15683854875644328975643872 You missed my point. Using SSH keys avoids the need to specify a username and password. Instead the key is used to authenticate with the remote server. Most importantly you avoid hard coding passwords into your script. The truly paranoid would generate SSH keys with passphrases and use an ssh-agent to cache the keys in memory. – Mark O'Connor Sep 06 '12 at 18:21
  • OK, in my script I am using scp ant ssh tasks, but my script is finished so now I don't want to change anything. Thanks for your method, maybe I will use it another time, greets. – user15683854875644328975643872 Sep 07 '12 at 08:22