From aec6748c25956c02010016d4550662d818c1eac9 Mon Sep 17 00:00:00 2001 From: Rory Winston Date: Tue, 30 Jan 2007 10:47:32 +0000 Subject: [PATCH 01/14] Fix licenses git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/net/branches/JDK_1_5_BRANCH@501365 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/commons/net/ftp/AllTests.java | 13 +++++++------ .../apache/commons/net/ftp/parser/AllTests.java | 16 +++++++++++++--- .../net/telnet/TelnetTestSimpleServer.java | 13 +++++++------ 3 files changed, 27 insertions(+), 15 deletions(-) diff --git a/src/test/java/org/apache/commons/net/ftp/AllTests.java b/src/test/java/org/apache/commons/net/ftp/AllTests.java index 2b07eb3e6..8cd3ebc13 100644 --- a/src/test/java/org/apache/commons/net/ftp/AllTests.java +++ b/src/test/java/org/apache/commons/net/ftp/AllTests.java @@ -1,11 +1,12 @@ /* - * Copyright 2005 The Apache Software Foundation + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/src/test/java/org/apache/commons/net/ftp/parser/AllTests.java b/src/test/java/org/apache/commons/net/ftp/parser/AllTests.java index ba531d331..38aadf200 100644 --- a/src/test/java/org/apache/commons/net/ftp/parser/AllTests.java +++ b/src/test/java/org/apache/commons/net/ftp/parser/AllTests.java @@ -1,8 +1,18 @@ /* - * Created on Apr 5, 2004 + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at * - * To change the template for this generated file go to - * Window - Preferences - Java - Code Generation - Code and Comments + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.commons.net.ftp.parser; diff --git a/src/test/java/org/apache/commons/net/telnet/TelnetTestSimpleServer.java b/src/test/java/org/apache/commons/net/telnet/TelnetTestSimpleServer.java index 8fab57d98..d564c2541 100644 --- a/src/test/java/org/apache/commons/net/telnet/TelnetTestSimpleServer.java +++ b/src/test/java/org/apache/commons/net/telnet/TelnetTestSimpleServer.java @@ -1,11 +1,12 @@ /* - * Copyright 2003-2004 The Apache Software Foundation + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, From cef37b2ab05fe2fd347a354fd8dbeee3687fed92 Mon Sep 17 00:00:00 2001 From: Rory Winston Date: Wed, 31 Jan 2007 09:26:35 +0000 Subject: [PATCH 02/14] Fix META-INF deployment and catch a likely exception in TestConnectTimeout.java git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/net/branches/JDK_1_5_BRANCH@501780 13f79535-47bb-0310-9956-ffa450edef68 --- pom.xml | 4 ++-- .../java/org/apache/commons/net/ftp/TestConnectTimeout.java | 6 +++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index ebf1201bf..ab4dde279 100644 --- a/pom.xml +++ b/pom.xml @@ -201,11 +201,11 @@ limitations under the License. - + - + diff --git a/src/test/java/org/apache/commons/net/ftp/TestConnectTimeout.java b/src/test/java/org/apache/commons/net/ftp/TestConnectTimeout.java index 895a547b1..46ccb93d0 100644 --- a/src/test/java/org/apache/commons/net/ftp/TestConnectTimeout.java +++ b/src/test/java/org/apache/commons/net/ftp/TestConnectTimeout.java @@ -19,6 +19,7 @@ import java.io.IOException; import java.net.SocketException; import java.net.SocketTimeoutException; +import java.net.UnknownHostException; import junit.framework.TestCase; @@ -41,6 +42,9 @@ public void testConnectTimeout() throws SocketException, IOException { catch (SocketTimeoutException se) { assertTrue(true); } - + catch (UnknownHostException uhe) { + // This is most likely a firewall/DNS issue, so let's just pass the test + } + } } From ad92bbeaf161bf3e038c6ca714247cdaa0111c65 Mon Sep 17 00:00:00 2001 From: Rory Winston Date: Thu, 15 Feb 2007 22:22:52 +0000 Subject: [PATCH 03/14] * Remove plugin repo * Add rel notes * Add patch for NET-151 git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/net/branches/JDK_1_5_BRANCH@508201 13f79535-47bb-0310-9956-ffa450edef68 --- RELEASE-NOTES.txt | 1 + pom.xml | 8 -------- .../org/apache/commons/net/ftp/FTPClient.java | 20 ++++++++++++++++++- 3 files changed, 20 insertions(+), 9 deletions(-) create mode 100644 RELEASE-NOTES.txt diff --git a/RELEASE-NOTES.txt b/RELEASE-NOTES.txt new file mode 100644 index 000000000..c66c316dd --- /dev/null +++ b/RELEASE-NOTES.txt @@ -0,0 +1 @@ +Please see the commons-net web site for a full changelist in this version. diff --git a/pom.xml b/pom.xml index ab4dde279..b2b7a0689 100644 --- a/pom.xml +++ b/pom.xml @@ -31,14 +31,6 @@ limitations under the License. 2-SNAPSHOT - - - - snapshots - http://people.apache.org/maven-snapshot-repository/ - - - http://jakarta.apache.org/commons/net/ 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 04c0ff72b..d0fc24373 100644 --- a/src/main/java/org/apache/commons/net/ftp/FTPClient.java +++ b/src/main/java/org/apache/commons/net/ftp/FTPClient.java @@ -274,6 +274,7 @@ public class FTPClient extends FTP private FTPFileEntryParserFactory __parserFactory; private int __bufferSize; private boolean __listHiddenFiles; + private InetAddress __overrideHostForPassiveConnections; // __systemName is a cached value that should not be referenced directly // except when assigned in getSystemName and __initDefaults. @@ -513,7 +514,10 @@ protected Socket _openDataConnection_(int command, String arg) __parsePassiveModeReply((String)_replyLines.get(_replyLines.size() - 1)); - socket = _socketFactory_.createSocket(__passiveHost, __passivePort); + String host = __passiveHost; + if(__overrideHostForPassiveConnections != null) + host = __overrideHostForPassiveConnections.getHostAddress(); + socket = _socketFactory_.createSocket(host, __passivePort); if ((__restartOffset > 0) && !restart(__restartOffset)) { socket.close(); @@ -621,6 +625,20 @@ public boolean isRemoteVerificationEnabled() return __remoteVerificationEnabled; } + /*** + * Override the host used for passive mode data connections. + * The default is to use the host given by the FTP server. + * You may set this value at any time, whether the + * FTPClient is currently connected or not. + *

+ * @param host The inet address of the host to use or null to + * disable overriding. + ***/ + public void overrideHostForPassiveConnections(InetAddress host) + { + __overrideHostForPassiveConnections = host; + } + /*** * Login to the FTP server using the provided username and password. *

From eb6ec2e9874dd5b408f89a254aafa2626bf1038e Mon Sep 17 00:00:00 2001 From: Rory Winston Date: Thu, 15 Feb 2007 22:36:22 +0000 Subject: [PATCH 04/14] Update release notes git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/net/branches/JDK_1_5_BRANCH@508214 13f79535-47bb-0310-9956-ffa450edef68 --- src/main/java/org/apache/commons/net/ftp/FTPClient.java | 1 - src/site/xdoc/changes.xml | 3 +++ 2 files changed, 3 insertions(+), 1 deletion(-) 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 d0fc24373..8d6dfabda 100644 --- a/src/main/java/org/apache/commons/net/ftp/FTPClient.java +++ b/src/main/java/org/apache/commons/net/ftp/FTPClient.java @@ -27,7 +27,6 @@ import java.net.ServerSocket; import java.net.Socket; import java.util.ArrayList; -import java.util.Arrays; import org.apache.commons.net.MalformedServerReplyException; import org.apache.commons.net.ftp.parser.DefaultFTPFileEntryParserFactory; diff --git a/src/site/xdoc/changes.xml b/src/site/xdoc/changes.xml index c23dc3396..94476548c 100644 --- a/src/site/xdoc/changes.xml +++ b/src/site/xdoc/changes.xml @@ -23,6 +23,9 @@ limitations under the License. + + Add support for explictly overriding destination hosts for passive sessions. Thanks to <neil@JAMMConsulting.com> + Add null check in TelnetClient::disconnect(). From 62e40452d71a4d7c0b6c237b905fa284c0e26363 Mon Sep 17 00:00:00 2001 From: Rory Winston Date: Thu, 29 Mar 2007 15:37:00 +0000 Subject: [PATCH 05/14] Fix NET-155 git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/net/branches/JDK_1_5_BRANCH@523750 13f79535-47bb-0310-9956-ffa450edef68 --- .../java/examples/nntp/ExtendedNNTPOps.java | 4 +- .../java/examples/nntp/MessageThreading.java | 4 +- src/main/java/examples/nntp/NNTPUtils.java | 2 +- .../apache/commons/net/nntp/NNTPClient.java | 10 +- .../commons/net/nntp/NewsgroupInfo.java | 234 +++++++++--------- src/site/xdoc/changes.xml | 3 + 6 files changed, 127 insertions(+), 130 deletions(-) diff --git a/src/main/java/examples/nntp/ExtendedNNTPOps.java b/src/main/java/examples/nntp/ExtendedNNTPOps.java index 26cf4c0f8..bd5c2cace 100644 --- a/src/main/java/examples/nntp/ExtendedNNTPOps.java +++ b/src/main/java/examples/nntp/ExtendedNNTPOps.java @@ -57,8 +57,8 @@ public void demo(String host, String user, String password) { // XOVER NewsgroupInfo testGroup = new NewsgroupInfo(); client.selectNewsgroup("alt.test", testGroup); - int lowArticleNumber = testGroup.getFirstArticle(); - int highArticleNumber = lowArticleNumber + 100; + long lowArticleNumber = testGroup.getFirstArticle(); + long highArticleNumber = lowArticleNumber + 100; Article[] articles = NNTPUtils.getArticleInfo(client, lowArticleNumber, highArticleNumber); for (int i = 0; i < articles.length; ++i) { diff --git a/src/main/java/examples/nntp/MessageThreading.java b/src/main/java/examples/nntp/MessageThreading.java index 50ee7785d..0c36d62ac 100644 --- a/src/main/java/examples/nntp/MessageThreading.java +++ b/src/main/java/examples/nntp/MessageThreading.java @@ -54,8 +54,8 @@ public static void main(String[] args) throws SocketException, IOException { NewsgroupInfo group = new NewsgroupInfo(); client.selectNewsgroup("comp.lang.lisp", group); - int lowArticleNumber = group.getFirstArticle(); - int highArticleNumber = lowArticleNumber + 100; + long lowArticleNumber = group.getFirstArticle(); + long highArticleNumber = lowArticleNumber + 100; System.out.println("Retrieving articles between [" + lowArticleNumber + "] and [" + highArticleNumber + "]"); Article[] articles = NNTPUtils.getArticleInfo(client, lowArticleNumber, highArticleNumber); diff --git a/src/main/java/examples/nntp/NNTPUtils.java b/src/main/java/examples/nntp/NNTPUtils.java index 18ca41740..bd570a277 100644 --- a/src/main/java/examples/nntp/NNTPUtils.java +++ b/src/main/java/examples/nntp/NNTPUtils.java @@ -42,7 +42,7 @@ public class NNTPUtils { * @return Article[] An array of Article * @throws IOException */ - public static Article[] getArticleInfo(NNTPClient client, int lowArticleNumber, int highArticleNumber) + public static Article[] getArticleInfo(NNTPClient client, long lowArticleNumber, long highArticleNumber) throws IOException { Reader reader = null; Article[] articles = null; diff --git a/src/main/java/org/apache/commons/net/nntp/NNTPClient.java b/src/main/java/org/apache/commons/net/nntp/NNTPClient.java index 96ec72539..cc9ace11b 100644 --- a/src/main/java/org/apache/commons/net/nntp/NNTPClient.java +++ b/src/main/java/org/apache/commons/net/nntp/NNTPClient.java @@ -176,7 +176,7 @@ private NewsgroupInfo __parseNewsgroupListEntry(String entry) { NewsgroupInfo result; StringTokenizer tokenizer; - int lastNum, firstNum; + long lastNum, firstNum; String last, first, permission; result = new NewsgroupInfo(); @@ -192,8 +192,8 @@ private NewsgroupInfo __parseNewsgroupListEntry(String entry) try { - lastNum = Integer.parseInt(last); - firstNum = Integer.parseInt(first); + lastNum = Long.valueOf(last); + firstNum = Long.valueOf(first); result._setFirstArticle(firstNum); result._setLastArticle(lastNum); @@ -1212,8 +1212,8 @@ public Reader retrieveArticleInfo(int articleNumber) throws IOException * @return a DotTerminatedReader if successful, null otherwise * @throws IOException */ - public Reader retrieveArticleInfo(int lowArticleNumber, - int highArticleNumber) + public Reader retrieveArticleInfo(long lowArticleNumber, + long highArticleNumber) throws IOException { return diff --git a/src/main/java/org/apache/commons/net/nntp/NewsgroupInfo.java b/src/main/java/org/apache/commons/net/nntp/NewsgroupInfo.java index dea53287e..538e11f61 100644 --- a/src/main/java/org/apache/commons/net/nntp/NewsgroupInfo.java +++ b/src/main/java/org/apache/commons/net/nntp/NewsgroupInfo.java @@ -32,124 +32,118 @@ * @see NNTPClient ***/ -public final class NewsgroupInfo -{ - /*** - * A constant indicating that the posting permission of a newsgroup is - * unknown. For example, the NNTP GROUP command does not return posting - * information, so NewsgroupInfo instances obtained from that command - * willhave an UNKNOWN_POSTING_PERMISSION. - ***/ - public static final int UNKNOWN_POSTING_PERMISSION = 0; - - /*** A constant indicating that a newsgroup is moderated. ***/ - public static final int MODERATED_POSTING_PERMISSION = 1; - - /*** A constant indicating that a newsgroup is public and unmoderated. ***/ - public static final int PERMITTED_POSTING_PERMISSION = 2; - - /*** - * A constant indicating that a newsgroup is closed for general posting. - ***/ - public static final int PROHIBITED_POSTING_PERMISSION = 3; - - private String __newsgroup; - private int __estimatedArticleCount; - private int __firstArticle, __lastArticle; - private int __postingPermission; - - void _setNewsgroup(String newsgroup) - { - __newsgroup = newsgroup; - } - - void _setArticleCount(int count) - { - __estimatedArticleCount = count; - } - - void _setFirstArticle(int first) - { - __firstArticle = first; - } - - void _setLastArticle(int last) - { - __lastArticle = last; - } - - void _setPostingPermission(int permission) - { - __postingPermission = permission; - } - - /*** - * Get the newsgroup name. - *

- * @return The name of the newsgroup. - ***/ - public String getNewsgroup() - { - return __newsgroup; - } - - /*** - * Get the estimated number of articles in the newsgroup. The - * accuracy of this value will depend on the server implementation. - *

- * @return The estimated number of articles in the newsgroup. - ***/ - public int getArticleCount() - { - return __estimatedArticleCount; - } - - /*** - * Get the number of the first article in the newsgroup. - *

- * @return The number of the first article in the newsgroup. - ***/ - public int getFirstArticle() - { - return __firstArticle; - } - - /*** - * Get the number of the last article in the newsgroup. - *

- * @return The number of the last article in the newsgroup. - ***/ - public int getLastArticle() - { - return __lastArticle; - } - - /*** - * Get the posting permission of the newsgroup. This will be one of - * the POSTING_PERMISSION constants. - *

- * @return The posting permission status of the newsgroup. - ***/ - public int getPostingPermission() - { - return __postingPermission; - } - - /* - public String toString() { - StringBuffer buffer = new StringBuffer(); - buffer.append(__newsgroup); - buffer.append(' '); - buffer.append(__lastArticle); - buffer.append(' '); - buffer.append(__firstArticle); - buffer.append(' '); - switch(__postingPermission) { - case 1: buffer.append('m'); break; - case 2: buffer.append('y'); break; - case 3: buffer.append('n'); break; - } - return buffer.toString(); -} - */ +public final class NewsgroupInfo { + /*** + * A constant indicating that the posting permission of a newsgroup is + * unknown. For example, the NNTP GROUP command does not return posting + * information, so NewsgroupInfo instances obtained from that command + * willhave an UNKNOWN_POSTING_PERMISSION. + ***/ + public static final int UNKNOWN_POSTING_PERMISSION = 0; + + /*** A constant indicating that a newsgroup is moderated. ***/ + public static final int MODERATED_POSTING_PERMISSION = 1; + + /*** A constant indicating that a newsgroup is public and unmoderated. ***/ + public static final int PERMITTED_POSTING_PERMISSION = 2; + + /*** + * A constant indicating that a newsgroup is closed for general posting. + ***/ + public static final int PROHIBITED_POSTING_PERMISSION = 3; + + private String __newsgroup; + private long __estimatedArticleCount; + private long __firstArticle, __lastArticle; + private int __postingPermission; + + void _setNewsgroup(String newsgroup) { + __newsgroup = newsgroup; + } + + void _setArticleCount(long count) { + __estimatedArticleCount = count; + } + + void _setFirstArticle(long first) { + __firstArticle = first; + } + + void _setLastArticle(long last) { + __lastArticle = last; + } + + void _setPostingPermission(int permission) { + __postingPermission = permission; + } + + /*** + * Get the newsgroup name. + *

+ * @return The name of the newsgroup. + ***/ + public String getNewsgroup() { + return __newsgroup; + } + + /*** + * Get the estimated number of articles in the newsgroup. The + * accuracy of this value will depend on the server implementation. + *

+ * @return The estimated number of articles in the newsgroup. + ***/ + public long getArticleCount() { + return __estimatedArticleCount; + } + + /*** + * Get the number of the first article in the newsgroup. + *

+ * @return The number of the first article in the newsgroup. + ***/ + public long getFirstArticle() { + return __firstArticle; + } + + /*** + * Get the number of the last article in the newsgroup. + *

+ * @return The number of the last article in the newsgroup. + ***/ + public long getLastArticle() { + return __lastArticle; + } + + /*** + * Get the posting permission of the newsgroup. This will be one of + * the POSTING_PERMISSION constants. + *

+ * @return The posting permission status of the newsgroup. + ***/ + public int getPostingPermission() { + return __postingPermission; + } + + public String toString() { + StringBuilder buffer = new StringBuilder(); + buffer.append(__newsgroup); + buffer.append(' '); + buffer.append(__lastArticle); + buffer.append(' '); + buffer.append(__firstArticle); + buffer.append(' '); + switch (__postingPermission) { + case 1: + buffer.append('m'); + break; + case 2: + buffer.append('y'); + break; + case 3: + buffer.append('n'); + break; + } + return buffer.toString(); + } + } diff --git a/src/site/xdoc/changes.xml b/src/site/xdoc/changes.xml index 94476548c..f4283d65f 100644 --- a/src/site/xdoc/changes.xml +++ b/src/site/xdoc/changes.xml @@ -23,6 +23,9 @@ limitations under the License. + + Change NNTPClient/NewsgroupInfo article counts from int to long + Add support for explictly overriding destination hosts for passive sessions. Thanks to <neil@JAMMConsulting.com> From 6e3463d14536a9336b2145eb26ed69a9269e48db Mon Sep 17 00:00:00 2001 From: Rory Winston Date: Wed, 11 Apr 2007 09:26:12 +0000 Subject: [PATCH 06/14] Fix javadoc error (NET-154) git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/net/branches/JDK_1_5_BRANCH@527430 13f79535-47bb-0310-9956-ffa450edef68 --- src/main/java/org/apache/commons/net/nntp/NNTPClient.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/apache/commons/net/nntp/NNTPClient.java b/src/main/java/org/apache/commons/net/nntp/NNTPClient.java index cc9ace11b..79848250f 100644 --- a/src/main/java/org/apache/commons/net/nntp/NNTPClient.java +++ b/src/main/java/org/apache/commons/net/nntp/NNTPClient.java @@ -54,7 +54,7 @@ * When that occurs, the NNTP class method encountering that reply will throw * an {@link org.apache.commons.net.nntp.NNTPConnectionClosedException} * . - * NNTPConectionClosedException + * NNTPConnectionClosedException * is a subclass of IOException and therefore need not be * caught separately, but if you are going to catch it separately, its * catch block must appear before the more general IOException From e5e43d72177c50e052b559a0ea74e92c6696aacf Mon Sep 17 00:00:00 2001 From: Rory Winston Date: Sun, 3 Jun 2007 19:05:55 +0000 Subject: [PATCH 07/14] Remove repo git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/net/branches/JDK_1_5_BRANCH@543963 13f79535-47bb-0310-9956-ffa450edef68 --- pom.xml | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/pom.xml b/pom.xml index b2b7a0689..6dd7699e5 100644 --- a/pom.xml +++ b/pom.xml @@ -58,16 +58,6 @@ limitations under the License. - - - jakarta - http://svn.apache.org/repos/asf/jakarta/commons/proper/net/trunk - - - maven-snapshots - http://people.apache.org/maven-snapshot-repository/ - - From 55bfc95a2aa1989a2949f51ed74dc1a2575d0867 Mon Sep 17 00:00:00 2001 From: Rory Winston Date: Sun, 3 Jun 2007 21:44:08 +0000 Subject: [PATCH 08/14] Attempt to provide a workaround for date rollback issue git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/net/branches/JDK_1_5_BRANCH@543998 13f79535-47bb-0310-9956-ffa450edef68 --- .../java/org/apache/commons/net/ftp/FTP.java | 5 +-- .../org/apache/commons/net/ftp/FTPClient.java | 23 +++++++++- .../commons/net/ftp/FTPClientConfig.java | 19 ++++++++ .../ftp/parser/FTPTimestampParserImpl.java | 21 ++++++++- .../commons/net/io/CopyStreamException.java | 8 ++++ src/site/xdoc/changes.xml | 8 ++++ .../parser/FTPTimestampParserImplTest.java | 43 +++++++++++++++++++ 7 files changed, 122 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/apache/commons/net/ftp/FTP.java b/src/main/java/org/apache/commons/net/ftp/FTP.java index ac297be58..27bed8bba 100644 --- a/src/main/java/org/apache/commons/net/ftp/FTP.java +++ b/src/main/java/org/apache/commons/net/ftp/FTP.java @@ -33,7 +33,7 @@ import org.apache.commons.net.SocketClient; /*** - * FTP provides the basic the functionality necessary to implement your + * FTP provides basic functionality necessary to implement your * own FTP client. It extends org.apache.commons.net.SocketClient since * extending TelnetClient was causing unwanted behavior (like connections * that did not time out properly). @@ -311,8 +311,7 @@ private void __getReply() throws IOException // returning too soon after encountering a naked CR or some other // anomaly. } - while (!(line.length() >= 4 && line.charAt(3) != '-' && - Character.isDigit(line.charAt(0)))); + while ((line.length() >= 4 || line.charAt(3) == '-' || !(line.substring(0,3).matches("\\d{3}")))); // This is too strong a condition because of non-conforming ftp // servers like ftp.funet.fi which sent 226 as the last line of a // 426 multi-line reply in response to ls /. We relax the condition to 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 8d6dfabda..66731415e 100644 --- a/src/main/java/org/apache/commons/net/ftp/FTPClient.java +++ b/src/main/java/org/apache/commons/net/ftp/FTPClient.java @@ -2431,7 +2431,7 @@ public void configure(FTPClientConfig config) { public void setListHiddenFiles(boolean listHiddenFiles) { this.__listHiddenFiles = listHiddenFiles; } - + /** * @see #setListHiddenFiles(boolean) * @return the current state @@ -2439,6 +2439,27 @@ public void setListHiddenFiles(boolean listHiddenFiles) { public boolean getListHiddenFiles() { return this.__listHiddenFiles; } + + /** + * + * @return + */ + public boolean isDateRollbackPermitted() { + return __configuration.isDateRollbackPermitted(); + } + + /** + * Set a boolean flag that specifies whether short date timestamps on the server + * (i.e. those with no year component) can be "rolled back" by a year if the server + * timestamp is greater than the local timestamp. This is true by default. + * + * @param dateRollbackPermitted false to explicitly prevent date rollback + */ + public void setDateRollbackPermitted(boolean dateRollbackPermitted) { + __configuration.setDateRollbackPermitted(dateRollbackPermitted); + } + + } /* Emacs configuration diff --git a/src/main/java/org/apache/commons/net/ftp/FTPClientConfig.java b/src/main/java/org/apache/commons/net/ftp/FTPClientConfig.java index 89754f012..360642ae8 100644 --- a/src/main/java/org/apache/commons/net/ftp/FTPClientConfig.java +++ b/src/main/java/org/apache/commons/net/ftp/FTPClientConfig.java @@ -192,6 +192,8 @@ public class FTPClientConfig private String shortMonthNames = null; private String serverTimeZoneId = null; + private boolean dateRollbackPermitted = true; + /** * The main constructor for an FTPClientConfig object @@ -554,5 +556,22 @@ public static Collection getSupportedLanguageCodes() { return LANGUAGE_CODE_MAP.keySet(); } + + /** + * getter for the {@link #dateRollbackPermitted} property + * @return + */ + public boolean isDateRollbackPermitted() { + return dateRollbackPermitted; + } + + /** + * @see FTPClient#setDateRollbackPermitted(boolean) + * + * @param dateRollbackPermitted true/false + */ + public void setDateRollbackPermitted(boolean dateRollbackPermitted) { + this.dateRollbackPermitted = dateRollbackPermitted; + } } diff --git a/src/main/java/org/apache/commons/net/ftp/parser/FTPTimestampParserImpl.java b/src/main/java/org/apache/commons/net/ftp/parser/FTPTimestampParserImpl.java index 497a1516c..53eca9108 100644 --- a/src/main/java/org/apache/commons/net/ftp/parser/FTPTimestampParserImpl.java +++ b/src/main/java/org/apache/commons/net/ftp/parser/FTPTimestampParserImpl.java @@ -26,6 +26,7 @@ import java.util.TimeZone; import org.apache.commons.net.ftp.Configurable; +import org.apache.commons.net.ftp.FTPClient; import org.apache.commons.net.ftp.FTPClientConfig; /** @@ -44,6 +45,7 @@ public class FTPTimestampParserImpl implements private SimpleDateFormat defaultDateFormat; private SimpleDateFormat recentDateFormat; private boolean lenientFutureDates = false; + private boolean dateRollbackPermitted = true; /** @@ -91,7 +93,7 @@ public Calendar parseTimestamp(String timestampStr) throws ParseException { // slightly in the future to roll back a full year. (Bug 35181) now.add(Calendar.DATE, 1); } - if (working.after(now)) { + if (working.after(now) && isDateRollbackPermitted()) { working.add(Calendar.YEAR, -1); } } else { @@ -244,6 +246,8 @@ public void configure(FTPClientConfig config) { setServerTimeZone(config.getServerTimeZoneId()); this.lenientFutureDates = config.isLenientFutureDates(); + + this.dateRollbackPermitted = config.isDateRollbackPermitted(); } /** * @return Returns the lenientFutureDates. @@ -257,4 +261,19 @@ boolean isLenientFutureDates() { void setLenientFutureDates(boolean lenientFutureDates) { this.lenientFutureDates = lenientFutureDates; } + + /** + * @returns the {@link #dateRollbackPermitted} property + */ + boolean isDateRollbackPermitted() { + return dateRollbackPermitted; + } + + /** + * @see FTPClient#setDateRollbackPermitted(boolean) + * @param dateRollbackPermitted + */ + void setDateRollbackPermitted(boolean dateRollbackPermitted) { + this.dateRollbackPermitted = dateRollbackPermitted; + } } diff --git a/src/main/java/org/apache/commons/net/io/CopyStreamException.java b/src/main/java/org/apache/commons/net/io/CopyStreamException.java index 49ef6c32f..974365bbf 100644 --- a/src/main/java/org/apache/commons/net/io/CopyStreamException.java +++ b/src/main/java/org/apache/commons/net/io/CopyStreamException.java @@ -68,4 +68,12 @@ public IOException getIOException() { return ioException; } + + /** + * Returns the original {@link IOException} + */ + @Override + public Throwable getCause() { + return getIOException(); + } } diff --git a/src/site/xdoc/changes.xml b/src/site/xdoc/changes.xml index f4283d65f..ceef8c660 100644 --- a/src/site/xdoc/changes.xml +++ b/src/site/xdoc/changes.xml @@ -23,6 +23,14 @@ limitations under the License. + + Add a setDateRollbackPermitted() method to disable rolling + back dates by 1 year when only short date format is + available, and server timstamp is ahead of local. + + + Add getCause() to CopyStreamException + Change NNTPClient/NewsgroupInfo article counts from int to long diff --git a/src/test/java/org/apache/commons/net/ftp/parser/FTPTimestampParserImplTest.java b/src/test/java/org/apache/commons/net/ftp/parser/FTPTimestampParserImplTest.java index c18bea387..9a3ae12df 100644 --- a/src/test/java/org/apache/commons/net/ftp/parser/FTPTimestampParserImplTest.java +++ b/src/test/java/org/apache/commons/net/ftp/parser/FTPTimestampParserImplTest.java @@ -158,6 +158,49 @@ public void testParseTimestampAcrossTimeZones() { } + public void testParseWithoutDateRollback() { + FTPTimestampParserImpl parser = new FTPTimestampParserImpl(); + + // Client calendar + Calendar now = Calendar.getInstance(); + + // Server calendar - same TZ, +1 hour drift + Calendar working = Calendar.getInstance(); + working.add(Calendar.HOUR_OF_DAY, 1); + + // Create a dummy timestamp + SimpleDateFormat formatter = new SimpleDateFormat("MMM d HH:mm"); + String timestamp = formatter.format(working.getTime()); + + Calendar server = null; + + try { + server = parser.parseTimestamp(timestamp); + } catch (ParseException e) { + e.printStackTrace(); + } + + // As the server's clock is (client clock + 1 hour), the date should have rolled back + // by a full year + assertTrue( server.get(Calendar.YEAR) == now.get(Calendar.YEAR) - 1 ); + + /* Now, we attempt to parse the same timestamp, but explicitly disallow */ + /* date rollback */ + + // Set property directly on parser (normally we would set it via the FTPClientConfig instance) + parser.setDateRollbackPermitted(false); + + try { + server = parser.parseTimestamp(timestamp); + } catch (ParseException e) { + e.printStackTrace(); + } + + // The local and remote year value should be equal + assertTrue( server.get(Calendar.YEAR) == now.get(Calendar.YEAR) ); + } + + public void testParser() { FTPTimestampParserImpl parser = new FTPTimestampParserImpl(); try { From d559d4111f8cc2f8dfcedf5ed018235656d09d54 Mon Sep 17 00:00:00 2001 From: Rory Winston Date: Wed, 6 Jun 2007 23:41:10 +0000 Subject: [PATCH 09/14] NET-158: Try to handle intermediate return code during authentication git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/net/branches/JDK_1_5_BRANCH@544992 13f79535-47bb-0310-9956-ffa450edef68 --- .../java/org/apache/commons/net/ftp/FTPClient.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) 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 66731415e..e0d84d89d 100644 --- a/src/main/java/org/apache/commons/net/ftp/FTPClient.java +++ b/src/main/java/org/apache/commons/net/ftp/FTPClient.java @@ -664,7 +664,16 @@ public boolean login(String username, String password) throws IOException if (!FTPReply.isPositiveIntermediate(_replyCode)) return false; - return FTPReply.isPositiveCompletion(pass(password)); + int replyCode = pass(password); + boolean replyOk = FTPReply.isPositiveCompletion(replyCode); + + // Work around stupid servers that send a 451 here + if (!replyOk && (replyCode == FTPReply.ACTION_ABORTED)) { + replyCode = getReply(); + replyOk = FTPReply.isPositiveCompletion(replyCode); + } + + return replyOk; } From 5fb00fd11b845ab152de2304fc7ff72606c7e5ce Mon Sep 17 00:00:00 2001 From: Rory Winston Date: Wed, 6 Jun 2007 23:50:21 +0000 Subject: [PATCH 10/14] Rollback git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/net/branches/JDK_1_5_BRANCH@544994 13f79535-47bb-0310-9956-ffa450edef68 --- src/main/java/org/apache/commons/net/ftp/FTP.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/apache/commons/net/ftp/FTP.java b/src/main/java/org/apache/commons/net/ftp/FTP.java index 27bed8bba..ac297be58 100644 --- a/src/main/java/org/apache/commons/net/ftp/FTP.java +++ b/src/main/java/org/apache/commons/net/ftp/FTP.java @@ -33,7 +33,7 @@ import org.apache.commons.net.SocketClient; /*** - * FTP provides basic functionality necessary to implement your + * FTP provides the basic the functionality necessary to implement your * own FTP client. It extends org.apache.commons.net.SocketClient since * extending TelnetClient was causing unwanted behavior (like connections * that did not time out properly). @@ -311,7 +311,8 @@ private void __getReply() throws IOException // returning too soon after encountering a naked CR or some other // anomaly. } - while ((line.length() >= 4 || line.charAt(3) == '-' || !(line.substring(0,3).matches("\\d{3}")))); + while (!(line.length() >= 4 && line.charAt(3) != '-' && + Character.isDigit(line.charAt(0)))); // This is too strong a condition because of non-conforming ftp // servers like ftp.funet.fi which sent 226 as the last line of a // 426 multi-line reply in response to ls /. We relax the condition to From 87766a2018df040a12b503af7041989605d30f50 Mon Sep 17 00:00:00 2001 From: Rory Winston Date: Wed, 6 Jun 2007 23:55:28 +0000 Subject: [PATCH 11/14] NET-158 git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/net/branches/JDK_1_5_BRANCH@544998 13f79535-47bb-0310-9956-ffa450edef68 --- src/site/xdoc/changes.xml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/site/xdoc/changes.xml b/src/site/xdoc/changes.xml index ceef8c660..52f86ecbe 100644 --- a/src/site/xdoc/changes.xml +++ b/src/site/xdoc/changes.xml @@ -23,6 +23,9 @@ limitations under the License. + + Added a workaround for intermediate 451 code in authentication. + Add a setDateRollbackPermitted() method to disable rolling back dates by 1 year when only short date format is From f14dd6177abd5ce57985a334bce692f60154884f Mon Sep 17 00:00:00 2001 From: Henri Yandell Date: Sun, 29 Jul 2007 03:40:41 +0000 Subject: [PATCH 12/14] Moving to TLP git-svn-id: https://svn.apache.org/repos/asf/commons/commons/proper/net/branches/JDK_1_5_BRANCH@560657 13f79535-47bb-0310-9956-ffa450edef68 From e0cc4959ef22057f76f03a71113cd6e943c94a46 Mon Sep 17 00:00:00 2001 From: Henri Yandell Date: Sun, 29 Jul 2007 03:42:34 +0000 Subject: [PATCH 13/14] Moving to TLP git-svn-id: https://svn.apache.org/repos/asf/commons/proper/net/branches/JDK_1_5_BRANCH@560660 13f79535-47bb-0310-9956-ffa450edef68 From 6990b361d6f6121e5bae539eea3204c4cefa16ae Mon Sep 17 00:00:00 2001 From: Sebastian Bazley Date: Thu, 10 Dec 2015 18:15:45 +0000 Subject: [PATCH 14/14] Obsolete DOAP git-svn-id: https://svn.apache.org/repos/asf/commons/proper/net/branches/JDK_1_5_BRANCH@1719162 13f79535-47bb-0310-9956-ffa450edef68 --- doap_net.rdf | 29 ----------------------------- 1 file changed, 29 deletions(-) delete mode 100644 doap_net.rdf diff --git a/doap_net.rdf b/doap_net.rdf deleted file mode 100644 index 5a205c8c6..000000000 --- a/doap_net.rdf +++ /dev/null @@ -1,29 +0,0 @@ - - - - Apache Jakarta Commons Net - - Java - - - - - - Jakarta Commons Net - - - - - - - - - - commons-net - 2005-12-03 - 1.4.1 - - - - -