2

I try to automate the deployment of a small site via ANT FTP. I use Win7-64bit and what started as an easy task gets more and more a challenge. I first figured out that I had to install additional classes which I did. commons-net-3.0.1.jar, jakarta-oro-2.0.8.jar Then I had to deactivate parts of my firewall which I also did. netsh advfirewall set global StatefulFTP disable But even now it is not working.

But step by step, that is the task:

<target name="ftp" description="">
<ftp server="${ftp.server}"
     userid="${ftp.user}"
     password="${ftp.password}"
     verbose="yes">
    <fileset dir="..">
        <include name="maintenance.php"/>
    </fileset>
</ftp>
</target>

Thats the result:

ftp:
  [ftp] sending files
  [ftp] transferring C:\xampp\htdocs\maintenance.php

BUILD FAILED
C:\xampp\htdocs\xdf\build.xml:32: could not put file: 425 Unable to build data con
nection: Connection timed out


Total time: 3 minutes 10 seconds

What the heck did I do wrong?

UPDATE found a working example for Zend auto-sync seams ANT 1.8.3 has new features:

<property name="ftp.server" value="ftp.foo.bar"/>
<property name="ftp.user" value="foor"/>
<property name="ftp.password" value="bar"/>
<property name="ftp.basedir" value=""/>
<property name="ftp.verbose" value="yes"/>

<target name="ftp-upload" description="Synchronise to FTP">
        <!-- Create temp folder -->
    <tempfile prefix="ant-epp-" destdir="${java.io.tmpdir}" property="temp.file"/>
    <mkdir dir="${temp.file}"/>

        <!-- Move, rename, upload, delete 'maintenance.php' -->
    <copy file="docs/hosting/maintenance.php" tofile="${temp.file}/index.php" />
    <ftp server="${ftp.server}"
            userid="${ftp.user}"
            password="${ftp.password}"
            remotedir="${ftp.basedir}/public"
            passive="yes"
            binary="yes"
            verbose="${ftp.verbose}">
        <fileset dir="${temp.file}">
            <include name="index.php" />
        </fileset>
    </ftp>
    <delete dir="${temp.file}" />

        <!-- Remove 'application' & Reupload -->
    <ftp action="del" server="${ftp.server}" userid="${ftp.user}" password="${ftp.password}"
            remotedir="${ftp.basedir}/application" passive="yes" binary="yes" verbose="${ftp.verbose}">
        <fileset>
            <include name="**" />
        </fileset>
    </ftp>
    <ftp action="rmdir" server="${ftp.server}" userid="${ftp.user}" password="${ftp.password}"
            remotedir="${ftp.basedir}/application" passive="yes" binary="yes" verbose="${ftp.verbose}">
        <fileset>
            <include name="**" />
        </fileset>
    </ftp>
    <ftp server="${ftp.server}" userid="${ftp.user}" password="${ftp.password}"
            remotedir="${ftp.basedir}/application" passive="yes" binary="yes" verbose="${ftp.verbose}">
        <fileset dir="application" />
    </ftp>

        <!-- Replace 'index.php' -->
    <ftp server="${ftp.server}" userid="${ftp.user}" password="${ftp.password}"
            remotedir="${ftp.basedir}/public" passive="yes" binary="yes" verbose="${ftp.verbose}">
        <fileset dir="public">
            <include name="index.php" />
        </fileset>
    </ftp>
</target>
5
  • 1
    Is an ftp connection possible with any other third party program?
    – FailedDev
    Nov 4, 2011 at 22:37
  • It was not planed to use something else but because of my frustration level I now think about a PHP script. Because it is a PHP based project.
    – lony
    Nov 5, 2011 at 17:52
  • I agree with @FailedDev, you should try to get file with help of another tool (FileZilla, for example)
    – Alex K
    Nov 5, 2011 at 21:39
  • What FailedDev said is a classical approach to solve the problem. Since your FTP task in Ant doesn't work, you should check if other FTP softwares work or not. If they work, then try to examine the difference between Ant and FTP (like how your firewall treats them).
    – Dante WWWW
    Nov 7, 2011 at 1:52
  • Thanks guys, I tryed this allready WinSCP works like a charm and my second approach stackoverflow.com/questions/8022431/… works to a certain point. So it is not a gernerel FTP problem. It has to do with ANT or the system.
    – lony
    Nov 7, 2011 at 9:16

1 Answer 1

8

I suspect that you still have a firewall issue.

Where FTP goes through a firewall, it is generally helpful to use passive mode.

Many FTP clients (Filezilla to take one example of many) default to passive mode.

The Ant FTP Task defaults to active mode:

passive selects passive-mode ("yes") transfers, for better through-firewall connectivity, at the price of performance. Defaults to "no"

Try using passive="yes" in your Ant FTP task.

Quite a good explanation here:

425 Unable to build data connection: Connection timed out

This error can happen when trying to transfer a file or list a directory in Active (PORT) mode. The problem is usually solved by switching to Passive mode...

Explanation of the problem: In Active mode, the data connection is setup like this: The client sends a PORT command telling the server the port where it will be listening for the data connection. The server receives the PORT command and initiates a connection to the client's IP/port. However, if a firewall is blocking the incoming connection, then it will go unanswered, and the server will timeout waiting for the connection to be accepted.

I'm no firewall expect, but I think that the command you executed to configure your firewall (netsh advfirewall set global StatefulFTP disable) is what you would do if you wanted to run an FTP server on your Windows box behind a firewall. In your case, I think you are connecting from Windows as a client to a remote FTP server, so I think you could undo that command.

3
  • Thank you, it is working! So I can now activate my firewall again if I understand the technique the right way?
    – lony
    Nov 8, 2011 at 12:42
  • Glad it works. I have updated my answer in response to your question. Nov 8, 2011 at 13:05
  • It seam netsh advfirewall set global StatefulFTP disable is needed even if I use passiv mode. Just to clear this up.
    – lony
    Nov 8, 2011 at 16:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.