title: How can I specify the classpath in the build file of an ftp tasks
body: <p>I would like to specify the classpath for an fpt task directly in my Ant Build script. I tried the following:</p>
  
  <pre><code>&lt;target name="ftp-upload" depends="build-html"&gt;     
     &lt;echo message="Ftp upload started with user ${user}" /&gt;
  &lt;ftp verbose="yes" 
              remotedir="${ftp.dir}" 
      server="${server}"
              userid="${user}" 
      password="${password}" 
      depends="yes"&gt;
        &lt;fileset dir="${mystuff.dir}/.." /&gt;
       &lt;classpath refid="build.classpath" /&gt;
  &lt;/ftp&gt;
  &lt;/target&gt;
  </code></pre>
  
  <p>and </p>
  
  <pre><code>&lt;target name="ftp-upload" depends="build-html"&gt;     
   &lt;echo message="Ftp upload started with user ${user}" /&gt;
  &lt;ftp verbose="yes" 
              remotedir="${ftp.dir}" 
      server="${server}"
              userid="${user}" 
      password="${password}" 
      depends="yes"
              classpathref="build.classpath"
       &gt;
        &lt;fileset dir="${mystuff.dir}/.." /&gt;
  &lt;/ftp&gt;
  &lt;/target&gt;
  </code></pre>
  
  <p>The first approach gives me the following error message:</p>
  
  <pre><code>Could not create type ftp due to java.lang.NoClassDefFoundError:      org/apache/commons/net/ftp/FTPClientConfig
  </code></pre>
  
  <p>The second approach gives me the following error message:</p>
  
  <pre><code>ftp doesn't support the "classpathref" attribute
  </code></pre>
  
  <p>Is it possible to set the classpath in the build script for the ftp tasks or do I have to do it outside the build script on my server? Would be nice to have the build script self-contained. </p>
  
  <p><strong>Solution:</strong></p>
  
  <p>Just re-define the ftp task with your classpath reference:</p>
  
  <pre><code>&lt;taskdef name="ftp" classname="org.apache.tools.ant.taskdefs.optional.net.FTP"&gt;
   &lt;classpath&gt;
      &lt;pathelement location="\lib\commons-net-1.4.0.jar"/&gt;
   &lt;/classpath&gt;
  &lt;/taskdef&gt;
  </code></pre>