JDK-6519647 : Unable to write files to FTP-server using URLConnection and HTTP Proxy
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.net
  • Affected Version: 6
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_2003
  • CPU: x86
  • Submitted: 2007-01-31
  • Updated: 2011-02-16
  • Resolved: 2009-10-21
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 7
7Resolved
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
java version "1.6.0"
Java(TM) SE Runtime Environment (build 1.6.0-b105)
Java HotSpot(TM) Client VM (build 1.6.0-b105, mixed mode, sharing)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 5.2.3790]

EXTRA RELEVANT SYSTEM CONFIGURATION :
Internet - Standard FTP Server
DMZ - Apache HTTP Server, using mod_proxy as HTTP proxy server
Local network - Client machine running the java app where exception occur.

A DESCRIPTION OF THE PROBLEM :
I'm trying to write a file from my client app via an HTTP proxy to a FTP server on the Internet.


STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Use supplied test program using your own URL and HTTP proxy server.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Create a new file on the FTP server named text.txt containing "Test".
ACTUAL -
The error message.

ERROR MESSAGES/STACK TRACES THAT OCCUR :
java.net.ProtocolException: cannot write to a URLConnection if doOutput=false -
call setDoOutput(true)
        at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(Unknown Source)
        at sun.net.www.protocol.ftp.FtpURLConnection.getOutputStream(Unknown Source)
        at FtpTest.main(FtpTest.java:24)

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.io.OutputStream;
import java.net.InetSocketAddress;
import java.net.Proxy;
import java.net.URL;
import java.net.URLConnection;
import java.net.Proxy.Type;

public class FtpTest
{

   private static final String FILE_URL = "ftp://user:###@###.###/test.txt";

   public static void main(String[] args)
   {
      try
      {
         URL url = new URL(FILE_URL);
         Proxy proxy = new Proxy(Type.HTTP, new InetSocketAddress("proxy", 8080));
         URLConnection connection = url.openConnection(proxy);
         connection.setDoOutput(true);
         OutputStream outputStream = connection.getOutputStream();
         outputStream.write("Test".getBytes());
         outputStream.close();
      }
      catch (Exception e)
      {
         e.printStackTrace();
      }
   }
}

---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Using a 3rd party ftp package.

Comments
EVALUATION This has been fixed while doing 6893702. So closing as a duplicate.
21-10-2009

EVALUATION Yes, FTPUrlConnection is not delegating correctly to the HTTP proxy in that particular case. However many HTTP proxies do not support that kind of request. Will fix in jdk7.
05-02-2007