Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6519647

Unable to write files to FTP-server using URLConnection and HTTP Proxy

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • 7
    • 6
    • core-libs
    • x86
    • windows_2003

      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.

            jccollet Jean-Christophe Collet (Inactive)
            ndcosta Nelson Dcosta (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: