Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ant FTP task fails: java.net.SocketException

Tags:

ant

ftp

I am trying to, with Ant, upload a zip-file via FTP to a Windows Server 2008 R2 FTP server (if it matters). I have a similar task to create the directory /Release, which works, yet somehow uploading via FTP gives me problems.

    <ftp    action="put"
            userid="${adapter.ftp.username}" 
            password="${adapter.ftp.password}"
            server="${ftp.hostname}"
            retriesAllowed="5"
            verbose="true"
            systemTypeKey="WINDOWS"
            remotedir="/Release" >

        <fileset dir=".">
            <include name="Adapter.zip"/>
        </fileset>
    </ftp>

The Ant debug log:

  [ftp] Opening FTP connection to 192.168.2.120
  [ftp] custom configuration
  [ftp] custom config: system key = WINDOWS
  [ftp] custom config: server language code = 
  [ftp] connected
  [ftp] logging in to FTP server
  [ftp] login succeeded
  [ftp] changing the remote directory to /Release
  [ftp] sending files
  fileset: Setup scanner in dir C:\dir with patternSet{ includes: [adapter.zip] excludes: [] }
  [ftp] transferring C:\dir\adapter.zip
  [ftp] try #1: IO error (adapter.zip), retrying
  /.../
  [ftp] try #6: IO error (adapter.zip), number of maximum retries reached (5), giving up
  [ftp] disconnecting
  build.xml:165: error during FTP transfer: java.net.SocketException: Software caused connection abort: socket write error
at org.apache.tools.ant.taskdefs.optional.net.FTP.execute(FTP.java:2538)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
at org.apache.tools.ant.Task.perform(Task.java:348)
at org.apache.tools.ant.Target.execute(Target.java:390)
at org.apache.tools.ant.Target.performTasks(Target.java:411)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399)
at org.apache.tools.ant.Project.executeTarget(Project.java:1368)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
at org.eclipse.ant.internal.launching.remote.EclipseDefaultExecutor.executeTargets(EclipseDefaultExecutor.java:32)
at org.apache.tools.ant.Project.executeTargets(Project.java:1251)
at org.eclipse.ant.internal.launching.remote.InternalAntRunner.run(InternalAntRunner.java:424)
at org.eclipse.ant.internal.launching.remote.InternalAntRunner.main(InternalAntRunner.java:138)
   Caused by: java.net.SocketException: Software caused connection abort: socket write error
at java.net.SocketOutputStream.socketWrite0(Native Method)
at java.net.SocketOutputStream.socketWrite(Unknown Source)
at java.net.SocketOutputStream.write(Unknown Source)
at sun.nio.cs.StreamEncoder.writeBytes(Unknown Source)
at sun.nio.cs.StreamEncoder.implFlushBuffer(Unknown Source)
at sun.nio.cs.StreamEncoder.implFlush(Unknown Source)
at sun.nio.cs.StreamEncoder.flush(Unknown Source)
at java.io.OutputStreamWriter.flush(Unknown Source)
at java.io.BufferedWriter.flush(Unknown Source)
at org.apache.commons.net.ftp.FTP.sendCommand(FTP.java:472)
at org.apache.commons.net.ftp.FTP.sendCommand(FTP.java:534)
at org.apache.commons.net.ftp.FTP.port(FTP.java:862)
at org.apache.commons.net.ftp.FTPClient._openDataConnection_(FTPClient.java:463)
at org.apache.commons.net.ftp.FTPClient.__storeFile(FTPClient.java:374)
at org.apache.commons.net.ftp.FTPClient.storeFile(FTPClient.java:1379)
at org.apache.tools.ant.taskdefs.optional.net.FTP.sendFile(FTP.java:2149)
at org.apache.tools.ant.taskdefs.optional.net.FTP$2.execute(FTP.java:1792)
at org.apache.tools.ant.util.RetryHandler.execute(RetryHandler.java:57)
at org.apache.tools.ant.taskdefs.optional.net.FTP.executeRetryable(FTP.java:1709)
at org.apache.tools.ant.taskdefs.optional.net.FTP.transferFiles(FTP.java:1788)
at org.apache.tools.ant.taskdefs.optional.net.FTP.transferFiles(FTP.java:1845)
at org.apache.tools.ant.taskdefs.optional.net.FTP.execute(FTP.java:2534)
... 15 more

What am I doing wrong?

like image 338
Oskar Ferm Avatar asked Dec 22 '11 16:12

Oskar Ferm


2 Answers

Turning off the Windows firewall resolved the issue.

like image 165
Oskar Ferm Avatar answered Oct 27 '22 13:10

Oskar Ferm


One thing worth trying is passive ftp. The Ant ftp task has a passive attribute for this:

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

There's a write up of the difference between active and passive mode here. The key point is that for ftp commands (including mkdir and the chdir that works in the OP question) a single open port - usually port 21 - is used. But for data transfers a different, possibly firewall-blocked port is used. Firewall-related problems with ftp can sometimes show the symptoms mentioned above.

like image 45
martin clayton Avatar answered Oct 27 '22 13:10

martin clayton