Ant build and empty directories

For some reason, when I use scp

to move files from my current computer to the server using ant

, it always ignores empty directories.

<scp todir="" keyfile="${basedir}\..\keys\prod_default.pem" trust="true">
<fileset dir="${staging.dir}" />


Why is that?

Full list of detailed updates:

D:\BUILD\SCRIPTS>ant -v -f getcom.xml update
Apache Ant(TM) version 1.8.2 compiled on December 20 2010
Buildfile: D:\BUILD\SCRIPTS\getcom.xml
Detected Java version: 1.7 in: C:\Program Files (x86)\Java\jdk1.7.0_02\jre
Detected OS: Windows Server 2008 R2
parsing buildfile D:\BUILD\SCRIPTS\getcom.xml with URI = file:/D:/BUILD/SCRIPTS/getcom.xml
Project base dir set to: D:\BUILD\SCRIPTS
parsing buildfile jar:file:/C:/ant/lib/ant.jar!/org/apache/tools/ant/antlib.xml
with URI = jar:file:/C:/ant/lib/ant.jar!/org/apache/tools/ant/antlib.xml from a zip file
 [property] Loading D:\BUILD\SCRIPTS\
Build sequence for target(s) `update' is [update]
Complete build sequence is [update, upload, cleanup, staging, export, init, ]

     [exec] Current OS is Windows Server 2008 R2
     [exec] Executing 'C:\\Program Files (x86)\\subversion\\bin\\\svn' with arguments:
     [exec] 'update'
     [exec] '--username'
     [exec] 'uuuu'
     [exec] '--password'
     [exec] 'uuuu'
     [exec] The ' characters around the executable and arguments are
     [exec] not part of the command.
     [exec] Updating 'D:\BUILD\_STAGING\GETOM':
     [exec] At revision 134.
      [scp] Connecting to xx.0.0.100:22
      [scp] done.
      [scp] Connecting to xx.0.2.100:22
      [scp] done.

Total time: 8 seconds



svn.bin=C://Program Files (x86)//subversion//bin//


Please note that the folder names have been changed.


source to share

1 answer

You will have to come up with a workaround. The way Ant implements scp means that empty directories are always skipped.

The bottom line is that the Scp class does this:

DirectoryScanner scanner = set.getDirectoryScanner(getProject());
Directory root = new Directory(scanner.getBasedir());
String[] files = scanner.getIncludedFiles();
if (files.length != 0) {


In other words, it only processes a directory if it contains at least one file.

There is a patch for the Scp task code , but that means a custom Ant construct.

Two other approaches that come to mind are

  • make directories non-empty by filling in placeholder files (which can be removed after deployment)
  • create empty directories in a separate step


All Articles