2

I am trying to copy files in remote serve to local using scp task in ant. The thing is, I want to exclude certain files with extension *.txt, so I tried using excludes tag. But it seems not to work. And It copies all the files including the files with extension *.txt

<scp file="username:pwd@remotemachine:/path/to/files/*" todir="copycontent" trust="true">
     <fileset dir="files" >
         <exclude name="**/*.txt"/>
     </fileset>
</scp>
DDK
  • 1,032
  • 18
  • 39

1 Answers1

5

The Ant SCP task has some limitations for your scenario:

  • "FileSet only works for copying files from the local machine to a remote machine." (from the Ant SCP manual page)
  • The SCP element itself does not provide attributes for includes/excludes patterns

So options for selective copying from remote to local are limited. More flexibility for copying from local to remote (using fileset).

Rather than excluding *.txt, you could instead include one or more file patterns one or more scp blocks.

Or an alternative if the local system is unix-based could be to exec rsync, as suggested in this answer to a similar question.

Community
  • 1
  • 1
ewan.chalmers
  • 16,145
  • 43
  • 60
  • when I remove the file attribute, I get a error message `'todir' and 'file' attributes must have syntax like the following: user:password@host:/path` – DDK Sep 18 '14 at 11:06