Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
ANT FTP任务抛出奇怪的错误_Ant_Ftp_Ant Contrib - Fatal编程技术网

ANT FTP任务抛出奇怪的错误

ANT FTP任务抛出奇怪的错误,ant,ftp,ant-contrib,Ant,Ftp,Ant Contrib,我对Ant1.9.1中的ftp任务有问题 这是我的ftp宏定义: <target name="checkAntCommons"> <!-- Test if ant commons-net jar is present --> <echo message="checking for ${ant.library.dir}/commons-net-1.4.1.jar"/> <if>

我对Ant1.9.1中的ftp任务有问题

这是我的ftp宏定义:

  <target name="checkAntCommons">
          <!-- Test if ant commons-net jar is present -->
          <echo message="checking for ${ant.library.dir}/commons-net-1.4.1.jar"/>
          <if>
            <available file="${ant.library.dir}/commons-net-1.4.1.jar" type="file" />
            <then>
                 <echo message="ANT commons-net library is available"/>
            </then>
            <else>
              <echo message="ANT commons-net library is not available" />
                 <copy file="${ANT_ROOT}/commons-net-1.4.1/commons-net-1.4.1.jar" todir="${ant.library.dir}"/>
                 <fail status="0" message="Must re-run build for changes to take effect" />
            </else>
          </if>
   </target>
   <target name="checkJakartaOro">
          <!-- Test if ant jakarta-oro jar is present -->
          <echo message="checking for ${ant.library.dir}/jakarta-oro-2.0.8.jar"/>
          <if>
            <available file="${ant.library.dir}/jakarta-oro-2.0.8.jar" type="file" />
            <then>
                 <echo message="jakarta-oro library is available"/>
            </then>
            <else>
              <echo message="jakarta-oro library is not available" />
                 <copy file="${ANT_ROOT}/jakarta-oro-2.0.8/jakarta-oro-2.0.8.jar" todir="${ant.library.dir}"/>
                 <fail status="0" message="Must re-run build for changes to take effect" />
            </else>
          </if>
   </target>

<macrodef name="deploySite" description="Deploy site files to ftp">
    <sequential>
        <antcall target="checkAntCommons"/>
        <antcall target="checkJakartaOro"/>
        <ftp userid="*******" password="*******" 
            server=***.***.***.***" 
            remotedir="/site/assets/foo"
            port="21"
            verbose="true"
            action="send"
            passive="yes"
            systemTypeKey="UNIX"
            >
            <fileset dir="./deploy">
                <includesfile name="deploy/foo.swf"/>
            </fileset>
        </ftp>
    </sequential>
</macrodef>
<target name="deploy" description="deploy foo files">
    <deploySite/>
</target>


答案是fileset元素错误:

<fileset dir="./deploy">
    <includesfile name="deploy/foo.swf"/>
</fileset>

该元素以某种方式读取垃圾,从而导致ant任务产生完全不可预测的响应

这样做:

<fileset>
    <include name="@{file-name}"/>
</fileset>

最终的工作解决方案是:

<macrodef name="deployFile" description="Deploy foo to *******">
    <attribute name="file-name" default="none" />
    <attribute name="path" default="." />
    <attribute name="remote-dir" default="." />
    <sequential>
        <property name="needToResend" value="false"/>
        <antcall target="checkAntCommons"/>
        <antcall target="checkJakartaOro"/>
        <trycatch>
            <try>
                <echo message="trying to upload ${basedir}/@{path}/@{file-name} to @{remote-dir}"/> 
                <sendFTPFile file-name="@{file-name}" path="${basedir}/@{path}" remote-dir="@{remote-dir}"/>
            </try>
            <catch>
                <echo message="${basedir}/@{path}/@{file-name} exists in @{remote-dir}"/> 
                <deleteFTPFile file-name="@{file-name}" remote-dir="@{remote-dir}"/>
                <property name="needToResend" value="true"/>
            </catch>
        </trycatch>
        <if>
            <equals arg1="${needToResend}" arg2="true"/>
            <then>
                <echo message="re-uploading ${basedir}/@{path}/@{file-name} to @{remote-dir}"/> 
                <sendFTPFile file-name="@{file-name}" path="${basedir}/@{path}" todir="@{remote-dir}"/>
            </then>
        </if>
    </sequential>
</macrodef>
<macrodef name="sendFTPFile" description="send a file to FTP">
    <attribute name="file-name" default="none" />
    <attribute name="path" default="." />
    <attribute name="remote-dir" default="." />
    <sequential>
        <echo message="sending @{path}/@{file-name} to @{remote-dir}"/>
        <ftp userid="****" password="********" 
            server="***.***.***.***" 
            remotedir="@{remote-dir}"
            port="21"
            verbose="true"
            action="send"
            passive="yes"
            systemTypeKey="UNIX"
            ignorenoncriticalerrors="true"
            >
            <fileset dir="@{path}">
                <include name="@{file-name}"/>
            </fileset>
        </ftp>
    </sequential>
</macrodef>
<macrodef name="deploySite">
    <sequential>
        <deployFile file-name="foo.bar" path="${DEPLOY_DIR}" remote-dir="/foo/bar/baz"/>
        <deployFile file-name="*.bar" path="${DEPLOY_DIR}/blah" remote-dir="/foo/bar/baz/blah"/>
    </sequential>
</macrodef>

<macrodef name="deployFile" description="Deploy foo to *******">
    <attribute name="file-name" default="none" />
    <attribute name="path" default="." />
    <attribute name="remote-dir" default="." />
    <sequential>
        <property name="needToResend" value="false"/>
        <antcall target="checkAntCommons"/>
        <antcall target="checkJakartaOro"/>
        <trycatch>
            <try>
                <echo message="trying to upload ${basedir}/@{path}/@{file-name} to @{remote-dir}"/> 
                <sendFTPFile file-name="@{file-name}" path="${basedir}/@{path}" remote-dir="@{remote-dir}"/>
            </try>
            <catch>
                <echo message="${basedir}/@{path}/@{file-name} exists in @{remote-dir}"/> 
                <deleteFTPFile file-name="@{file-name}" remote-dir="@{remote-dir}"/>
                <property name="needToResend" value="true"/>
            </catch>
        </trycatch>
        <if>
            <equals arg1="${needToResend}" arg2="true"/>
            <then>
                <echo message="re-uploading ${basedir}/@{path}/@{file-name} to @{remote-dir}"/> 
                <sendFTPFile file-name="@{file-name}" path="${basedir}/@{path}" todir="@{remote-dir}"/>
            </then>
        </if>
    </sequential>
</macrodef>
<macrodef name="sendFTPFile" description="send a file to FTP">
    <attribute name="file-name" default="none" />
    <attribute name="path" default="." />
    <attribute name="remote-dir" default="." />
    <sequential>
        <echo message="sending @{path}/@{file-name} to @{remote-dir}"/>
        <ftp userid="****" password="********" 
            server="***.***.***.***" 
            remotedir="@{remote-dir}"
            port="21"
            verbose="true"
            action="send"
            passive="yes"
            systemTypeKey="UNIX"
            ignorenoncriticalerrors="true"
            >
            <fileset dir="@{path}">
                <include name="@{file-name}"/>
            </fileset>
        </ftp>
    </sequential>
</macrodef>
<macrodef name="deploySite">
    <sequential>
        <deployFile file-name="foo.bar" path="${DEPLOY_DIR}" remote-dir="/foo/bar/baz"/>
        <deployFile file-name="*.bar" path="${DEPLOY_DIR}/blah" remote-dir="/foo/bar/baz/blah"/>
    </sequential>
</macrodef>