Uploaded image for project: 'Commons Net'
  1. Commons Net
  2. NET-324

ant ftp doesn't download files in subdirectories when remotedir is empty or root folder

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Invalid
    • 2.0
    • None
    • None
    • Windows 7, 64bit, apache-ant-1.8.1, commons-net-2.0, jakarta-oro-2.0.8, FileZilla Server version 0.9.34 beta

    Description

      I'm trying to download files in subdirectories from an ftp server with ant. The exact set of files is known. Some of them are in subdirectories. Ant only seems to download the ones in the root directory. It does work if I download all files without listing them.

      At first I thought I was doing something wrong so I posted a question on stackoverflow.
      http://stackoverflow.com/questions/2790570/ant-ftp-doesnt-download-files-in-subdirectories

      You can see my scriptdef workaround in the answers there.

      The first ftp action should do the exact same thing as the second. Instead I get "Hidden file \\a\a.txt assumed to not be a symlink."

      build.xml
      <?xml version="1.0" encoding="utf-8"?>
      <project name="example" default="example" basedir=".">
          <taskdef name="ftp" 
          classname="org.apache.tools.ant.taskdefs.optional.net.FTP" />
      
          <target name="example">
      
              <!-- doesn't work -->
              <ftp action="get" verbose="true"
              server="localhost" userid="example" password="example" 
              remotedir="">
                  <fileset dir="downloads" casesensitive="false" 
                  includes="a/a.txt,a/b/ab.txt,c/c.txt" />
              </ftp>
      
              <!-- works (but requires multiple ftp tasks) -->
              <ftp action="get" verbose="true"
              server="localhost" userid="example" password="example"
              remotedir="a">
                  <fileset dir="downloads" casesensitive="false" 
                  includes="a.txt,b/ab.txt" />
              </ftp>
              <ftp action="get" verbose="true"
              server="localhost" userid="example" password="example"
              remotedir="c">
                  <fileset dir="downloads" casesensitive="false" 
                  includes="c.txt" />
              </ftp>
      
          </target>
      
      </project>
      
      build-with-workaround.xml
      <?xml version="1.0" encoding="utf-8"?>
      <project name="example" default="example" basedir=".">
          <taskdef name="ftp" 
          classname="org.apache.tools.ant.taskdefs.optional.net.FTP" />
      
          <target name="example">
      <scriptdef name="my-ftp-get" language="javascript">
          <attribute name="server"/>
          <attribute name="userid"/>
          <attribute name="password"/>
          <attribute name="remotedir"/>
          <attribute name="fileset_dir"/>
          <attribute name="fileset_includes"/>
          <![CDATA[
          importClass(java.io.File);
          importClass(org.apache.tools.ant.taskdefs.optional.net.FTP);
          var local_basedir = "" + attributes.get("fileset_dir") + "/";
          var original_includes = "" + attributes.get("fileset_includes");
          var remotedir = "" + attributes.get("remotedir");
          local_basedir = local_basedir.replace(/\\/g, "/");
          original_includes = original_includes.replace(/\\/g, "/");
          remotedir = remotedir.replace(/\\/g, "/");
          var includes_arr = original_includes.split(",");
          var clean_includes = {};
          for (var i = 0; i < includes_arr.length; i++) {
              var directory = "/";
              var filename = includes_arr[i];
              var split_include = includes_arr[i].split("/");
              if (split_include.length > 1) {
                  directory = split_include[0] + "/";
                  filename = includes_arr[i].substring(directory.length);
              }
              if (!clean_includes.hasOwnProperty(directory)) {
                  clean_includes[directory] = [];
              }
              clean_includes[directory].push(filename);
          }
          var get_files = new FTP.Action();
          get_files.setValue("get");
          for (var path in clean_includes) {
              var current_clean_includes = clean_includes[path].join(",");
              var fileset = project.createDataType("fileset");
              var ftp = self.project.createTask("ftp");
              ftp.setAction(get_files);
              ftp.setServer(attributes.get("server"));
              ftp.setUserid(attributes.get("userid"));
              ftp.setPassword(attributes.get("password"));
              ftp.setRemotedir(remotedir + path);
              fileset.setDir(new File(local_basedir + path));
              fileset.setIncludes(current_clean_includes);
              ftp.addFileset(fileset);
              ftp.perform();
          }
          ]]>
      </scriptdef>
      
      <my-ftp-get
      server="localhost" userid="example" password="example"
      remotedir=""
          fileset_dir="downloads" casesensitive="false" 
          fileset_includes="a/a.txt,a/b/ab.txt,c/c.txt">
      </my-ftp-get>
      
          </target>
      
      </project>
      

      Attachments

        Activity

          People

            Unassigned Unassigned
            k.neirynck Kristof Neirynck
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: