This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-net.git


The following commit(s) were added to refs/heads/master by this push:
     new 63614fb  [NET-690] Performance issue when using the FTPClient to 
retrieve files #65.
63614fb is described below

commit 63614fbb06c2b86cd3287403f9e9d8b1ca5bb480
Author: Gary Gregory <garydgreg...@gmail.com>
AuthorDate: Tue Oct 13 11:52:24 2020 -0400

    [NET-690] Performance issue when using the FTPClient to retrieve files
    #65.
---
 src/changes/changes.xml                            |  6 ++---
 .../java/org/apache/commons/net/ftp/FTPClient.java | 28 ++++++++++++----------
 2 files changed, 18 insertions(+), 16 deletions(-)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index f96050a..3fb66fc 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -70,6 +70,9 @@ The <action> type attribute can be add,update,fix,remove.
             <action type="update" dev="ggregory" due-to="Dependabot">
             Fix possible socket and input stream leak on socket exception in 
org.apache.commons.net.ftp.FTPClient._retrieveFile(String, String, 
OutputStream).
             </action>
+            <action issue="NET-690" type="fix" dev="ggregory" 
due-to="payal-meh, Gary Gregory">
+            Performance issue when using the FTPClient to retrieve files #65.
+            </action>
             <!--  UPDATES -->
             <action type="update" dev="ggregory" due-to="Dependabot">
             Bump actions/setup-java from v1.4.2 to v1.4.3 #62.
@@ -83,9 +86,6 @@ The <action> type attribute can be add,update,fix,remove.
             <action type="update" dev="ggregory" due-to="Dependabot">
             Update actions/checkout from v2.3.1 to v2.3.3 #56, #61.
             </action>
-            <action type="update" dev="ggregory" due-to="Dependabot">
-            Update actions/setup-java from v1.4.0 to v1.4.2 #58.
-            </action>
         </release>
         <release version="3.7" date="2020-08-05" description="
 This is mainly a bug-fix release. See further details below.
diff --git a/src/main/java/org/apache/commons/net/ftp/FTPClient.java 
b/src/main/java/org/apache/commons/net/ftp/FTPClient.java
index 91704a4..3e14e1e 100644
--- a/src/main/java/org/apache/commons/net/ftp/FTPClient.java
+++ b/src/main/java/org/apache/commons/net/ftp/FTPClient.java
@@ -1902,24 +1902,26 @@ implements Configurable
         InputStream input = null;
         CSL csl = null;
         try {
-            if (fileType == ASCII_FILE_TYPE) {
-                input = new 
FromNetASCIIInputStream(getBufferedInputStream(socket.getInputStream()));
-            } else {
-                input = getBufferedInputStream(socket.getInputStream());
-            }
-
-            if (controlKeepAliveTimeout > 0) {
-                csl = new CSL(this, controlKeepAliveTimeout, 
controlKeepAliveReplyTimeout);
-            }
+            try {
+                if (fileType == ASCII_FILE_TYPE) {
+                    input = new 
FromNetASCIIInputStream(getBufferedInputStream(socket.getInputStream()));
+                } else {
+                    input = getBufferedInputStream(socket.getInputStream());
+                }
 
-            // Treat everything else as binary for now
-            Util.copyStream(input, local, getBufferSize(), 
CopyStreamEvent.UNKNOWN_STREAM_SIZE, mergeListeners(csl),
-                false);
+                if (controlKeepAliveTimeout > 0) {
+                    csl = new CSL(this, controlKeepAliveTimeout, 
controlKeepAliveReplyTimeout);
+                }
 
+                // Treat everything else as binary for now
+                Util.copyStream(input, local, getBufferSize(), 
CopyStreamEvent.UNKNOWN_STREAM_SIZE, mergeListeners(csl),
+                    false);
+            } finally {
+                Util.closeQuietly(input);
+            }
             // Get the transfer response
             return completePendingCommand();
         } finally {
-            Util.closeQuietly(input);
             Util.closeQuietly(socket);
             if (csl != null) {
                 cslDebug = csl.cleanUp(); // fetch any outstanding keepalive 
replies

Reply via email to