8170222: Better transfers of files
authorvtewari
Fri, 10 Feb 2017 10:11:10 +0530
changeset 44757 c5f03e77cd67
parent 44756 b887cb49e622
child 44758 e9f82f61bc22
8170222: Better transfers of files Reviewed-by: dfuchs, chegar
jdk/src/java.base/share/classes/sun/net/ftp/impl/FtpClient.java
--- a/jdk/src/java.base/share/classes/sun/net/ftp/impl/FtpClient.java	Fri Feb 03 14:10:33 2017 -0500
+++ b/jdk/src/java.base/share/classes/sun/net/ftp/impl/FtpClient.java	Fri Feb 10 10:11:10 2017 +0530
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2009, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2009, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -516,7 +516,8 @@
      * @return <code>true</code> if the command was successful
      * @throws IOException
      */
-    private boolean issueCommand(String cmd) throws IOException {
+    private boolean issueCommand(String cmd) throws IOException,
+            sun.net.ftp.FtpProtocolException {
         if (!isConnected()) {
             throw new IllegalStateException("Not connected");
         }
@@ -527,6 +528,12 @@
                 // ignore...
             }
         }
+        if (cmd.indexOf('\n') != -1) {
+            sun.net.ftp.FtpProtocolException ex
+                    = new sun.net.ftp.FtpProtocolException("Illegal FTP command");
+            ex.initCause(new IllegalArgumentException("Illegal carriage return"));
+            throw ex;
+        }
         sendServer(cmd + "\r\n");
         return readReply();
     }
@@ -1119,7 +1126,10 @@
      */
     public void close() throws IOException {
         if (isConnected()) {
-            issueCommand("QUIT");
+            try {
+                issueCommand("QUIT");
+            } catch (FtpProtocolException e) {
+            }
             loggedIn = false;
         }
         disconnect();
@@ -1897,7 +1907,8 @@
         return null;
     }
 
-    private boolean sendSecurityData(byte[] buf) throws IOException {
+    private boolean sendSecurityData(byte[] buf) throws IOException,
+            sun.net.ftp.FtpProtocolException {
         String s = Base64.getMimeEncoder().encodeToString(buf);
         return issueCommand("ADAT " + s);
     }