You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by se...@apache.org on 2013/01/23 20:07:11 UTC
svn commit: r1437631 - in /commons/proper/net/trunk/src: changes/
main/java/org/apache/commons/net/ftp/ test/java/org/apache/commons/net/ftp/
test/java/org/apache/commons/net/ftp/parser/
Author: sebb
Date: Wed Jan 23 19:07:10 2013
New Revision: 1437631
URL: http://svn.apache.org/viewvc?rev=1437631&view=rev
Log:
NET-310 FTPCommand conversion to use enum; added FTPCmd emum and deprecated FTPCommand.
Added:
commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/FTPCmd.java (with props)
Modified:
commons/proper/net/trunk/src/changes/changes.xml
commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/FTP.java
commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/FTPClient.java
commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/FTPCommand.java
commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/FTPHTTPClient.java
commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/FTPSClient.java
commons/proper/net/trunk/src/test/java/org/apache/commons/net/ftp/FTPCommandTest.java
commons/proper/net/trunk/src/test/java/org/apache/commons/net/ftp/parser/DownloadListings.java
Modified: commons/proper/net/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/net/trunk/src/changes/changes.xml?rev=1437631&r1=1437630&r2=1437631&view=diff
==============================================================================
--- commons/proper/net/trunk/src/changes/changes.xml (original)
+++ commons/proper/net/trunk/src/changes/changes.xml Wed Jan 23 19:07:10 2013
@@ -64,6 +64,9 @@ The <action> type attribute can be add,u
<body>
<release version="3.3" date="TBA" description="
">
+ <action issue="NET-310" dev="sebb" type="add">
+ FTPCommand conversion to use enum; added FTPCmd emum and deprecated FTPCommand.
+ </action>
<action issue="NET-480" dev="sebb" type="fix">
Wrong passivHost when using FTPHTTPClient with EPSV
</action>
Modified: commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/FTP.java
URL: http://svn.apache.org/viewvc/commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/FTP.java?rev=1437631&r1=1437630&r2=1437631&view=diff
==============================================================================
--- commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/FTP.java (original)
+++ commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/FTP.java Wed Jan 23 19:07:10 2013
@@ -525,7 +525,7 @@ public class FTP extends SocketClient
* @since 3.0
*/
protected void __noop() throws IOException {
- String msg = __buildMessage(FTPCommand.getCommand(FTPCommand.NOOP), null);
+ String msg = __buildMessage(FTPCmd.NOOP.getCommand(), null);
__send(msg);
__getReplyNoReport(); // This may timeout
}
@@ -550,12 +550,61 @@ public class FTP extends SocketClient
* as an IOException or independently as itself.
* @exception IOException If an I/O error occurs while either sending the
* command or receiving the server reply.
+ * @deprecated Use {@link #sendCommand(FTPCmd, String)} instead
***/
+ @Deprecated
public int sendCommand(int command, String args) throws IOException
{
return sendCommand(FTPCommand.getCommand(command), args);
}
+ /**
+ * Sends an FTP command to the server, waits for a reply and returns the
+ * numerical response code. After invocation, for more detailed
+ * information, the actual reply text can be accessed by calling
+ * {@link #getReplyString getReplyString } or
+ * {@link #getReplyStrings getReplyStrings }.
+ * <p>
+ * @param command The FTPCmd enum corresponding to the FTP command
+ * to send.
+ * @return The integer value of the FTP reply code returned by the server
+ * in response to the command.
+ * @exception FTPConnectionClosedException
+ * If the FTP server prematurely closes the connection as a result
+ * of the client being idle or some other reason causing the server
+ * to send FTP reply code 421. This exception may be caught either
+ * as an IOException or independently as itself.
+ * @exception IOException If an I/O error occurs while either sending the
+ * command or receiving the server reply.
+ */
+ public int sendCommand(FTPCmd command) throws IOException{
+ return sendCommand(command, null);
+ }
+
+ /**
+ * Sends an FTP command to the server, waits for a reply and returns the
+ * numerical response code. After invocation, for more detailed
+ * information, the actual reply text can be accessed by calling
+ * {@link #getReplyString getReplyString } or
+ * {@link #getReplyStrings getReplyStrings }.
+ * <p>
+ * @param command The FTPCmd enum corresponding to the FTP command
+ * to send.
+ * @param args The arguments to the FTP command. If this parameter is
+ * set to null, then the command is sent with no argument.
+ * @return The integer value of the FTP reply code returned by the server
+ * in response to the command.
+ * @exception FTPConnectionClosedException
+ * If the FTP server prematurely closes the connection as a result
+ * of the client being idle or some other reason causing the server
+ * to send FTP reply code 421. This exception may be caught either
+ * as an IOException or independently as itself.
+ * @exception IOException If an I/O error occurs while either sending the
+ * command or receiving the server reply.
+ */
+ public int sendCommand(FTPCmd command, String args) throws IOException{
+ return sendCommand(command.getCommand(), args);
+ }
/***
* Sends an FTP command with no arguments to the server, waits for a
@@ -699,7 +748,7 @@ public class FTP extends SocketClient
***/
public int user(String username) throws IOException
{
- return sendCommand(FTPCommand.USER, username);
+ return sendCommand(FTPCmd.USER, username);
}
/**
@@ -717,7 +766,7 @@ public class FTP extends SocketClient
*/
public int pass(String password) throws IOException
{
- return sendCommand(FTPCommand.PASS, password);
+ return sendCommand(FTPCmd.PASS, password);
}
/***
@@ -736,7 +785,7 @@ public class FTP extends SocketClient
***/
public int acct(String account) throws IOException
{
- return sendCommand(FTPCommand.ACCT, account);
+ return sendCommand(FTPCmd.ACCT, account);
}
@@ -755,7 +804,7 @@ public class FTP extends SocketClient
***/
public int abor() throws IOException
{
- return sendCommand(FTPCommand.ABOR);
+ return sendCommand(FTPCmd.ABOR);
}
/***
@@ -774,7 +823,7 @@ public class FTP extends SocketClient
***/
public int cwd(String directory) throws IOException
{
- return sendCommand(FTPCommand.CWD, directory);
+ return sendCommand(FTPCmd.CWD, directory);
}
/***
@@ -792,7 +841,7 @@ public class FTP extends SocketClient
***/
public int cdup() throws IOException
{
- return sendCommand(FTPCommand.CDUP);
+ return sendCommand(FTPCmd.CDUP);
}
/***
@@ -810,7 +859,7 @@ public class FTP extends SocketClient
***/
public int quit() throws IOException
{
- return sendCommand(FTPCommand.QUIT);
+ return sendCommand(FTPCmd.QUIT);
}
/***
@@ -828,7 +877,7 @@ public class FTP extends SocketClient
***/
public int rein() throws IOException
{
- return sendCommand(FTPCommand.REIN);
+ return sendCommand(FTPCmd.REIN);
}
/***
@@ -847,7 +896,7 @@ public class FTP extends SocketClient
***/
public int smnt(String dir) throws IOException
{
- return sendCommand(FTPCommand.SMNT, dir);
+ return sendCommand(FTPCmd.SMNT, dir);
}
/***
@@ -878,7 +927,7 @@ public class FTP extends SocketClient
num = port & 0xff;
info.append(num);
- return sendCommand(FTPCommand.PORT, info.toString());
+ return sendCommand(FTPCmd.PORT, info.toString());
}
/***
@@ -933,7 +982,7 @@ public class FTP extends SocketClient
info.append(port);
info.append("|");
- return sendCommand(FTPCommand.EPRT, info.toString());
+ return sendCommand(FTPCmd.EPRT, info.toString());
}
/***
@@ -953,7 +1002,7 @@ public class FTP extends SocketClient
***/
public int pasv() throws IOException
{
- return sendCommand(FTPCommand.PASV);
+ return sendCommand(FTPCmd.PASV);
}
/***
@@ -974,7 +1023,7 @@ public class FTP extends SocketClient
***/
public int epsv() throws IOException
{
- return sendCommand(FTPCommand.EPSV);
+ return sendCommand(FTPCmd.EPSV);
}
/**
@@ -1006,7 +1055,7 @@ public class FTP extends SocketClient
arg.append(__modes.charAt(formatOrByteSize));
}
- return sendCommand(FTPCommand.TYPE, arg.toString());
+ return sendCommand(FTPCmd.TYPE, arg.toString());
}
@@ -1027,7 +1076,7 @@ public class FTP extends SocketClient
*/
public int type(int fileType) throws IOException
{
- return sendCommand(FTPCommand.TYPE,
+ return sendCommand(FTPCmd.TYPE,
__modes.substring(fileType, fileType + 1));
}
@@ -1048,7 +1097,7 @@ public class FTP extends SocketClient
***/
public int stru(int structure) throws IOException
{
- return sendCommand(FTPCommand.STRU,
+ return sendCommand(FTPCmd.STRU,
__modes.substring(structure, structure + 1));
}
@@ -1069,7 +1118,7 @@ public class FTP extends SocketClient
***/
public int mode(int mode) throws IOException
{
- return sendCommand(FTPCommand.MODE,
+ return sendCommand(FTPCmd.MODE,
__modes.substring(mode, mode + 1));
}
@@ -1092,7 +1141,7 @@ public class FTP extends SocketClient
***/
public int retr(String pathname) throws IOException
{
- return sendCommand(FTPCommand.RETR, pathname);
+ return sendCommand(FTPCmd.RETR, pathname);
}
/***
@@ -1115,7 +1164,7 @@ public class FTP extends SocketClient
***/
public int stor(String pathname) throws IOException
{
- return sendCommand(FTPCommand.STOR, pathname);
+ return sendCommand(FTPCmd.STOR, pathname);
}
/***
@@ -1136,7 +1185,7 @@ public class FTP extends SocketClient
***/
public int stou() throws IOException
{
- return sendCommand(FTPCommand.STOU);
+ return sendCommand(FTPCmd.STOU);
}
/***
@@ -1159,7 +1208,7 @@ public class FTP extends SocketClient
*/
public int stou(String pathname) throws IOException
{
- return sendCommand(FTPCommand.STOU, pathname);
+ return sendCommand(FTPCmd.STOU, pathname);
}
/***
@@ -1182,7 +1231,7 @@ public class FTP extends SocketClient
***/
public int appe(String pathname) throws IOException
{
- return sendCommand(FTPCommand.APPE, pathname);
+ return sendCommand(FTPCmd.APPE, pathname);
}
/***
@@ -1201,7 +1250,7 @@ public class FTP extends SocketClient
***/
public int allo(int bytes) throws IOException
{
- return sendCommand(FTPCommand.ALLO, Integer.toString(bytes));
+ return sendCommand(FTPCmd.ALLO, Integer.toString(bytes));
}
/**
@@ -1214,7 +1263,7 @@ public class FTP extends SocketClient
*/
public int feat() throws IOException
{
- return sendCommand(FTPCommand.FEAT);
+ return sendCommand(FTPCmd.FEAT);
}
/***
@@ -1234,7 +1283,7 @@ public class FTP extends SocketClient
***/
public int allo(int bytes, int recordSize) throws IOException
{
- return sendCommand(FTPCommand.ALLO, Integer.toString(bytes) + " R " +
+ return sendCommand(FTPCmd.ALLO, Integer.toString(bytes) + " R " +
Integer.toString(recordSize));
}
@@ -1254,7 +1303,7 @@ public class FTP extends SocketClient
***/
public int rest(String marker) throws IOException
{
- return sendCommand(FTPCommand.REST, marker);
+ return sendCommand(FTPCmd.REST, marker);
}
@@ -1263,7 +1312,7 @@ public class FTP extends SocketClient
**/
public int mdtm(String file) throws IOException
{
- return sendCommand(FTPCommand.MDTM, file);
+ return sendCommand(FTPCmd.MDTM, file);
}
@@ -1286,7 +1335,7 @@ public class FTP extends SocketClient
**/
public int mfmt(String pathname, String timeval) throws IOException
{
- return sendCommand(FTPCommand.MFMT, timeval + " " + pathname);
+ return sendCommand(FTPCmd.MFMT, timeval + " " + pathname);
}
@@ -1306,7 +1355,7 @@ public class FTP extends SocketClient
***/
public int rnfr(String pathname) throws IOException
{
- return sendCommand(FTPCommand.RNFR, pathname);
+ return sendCommand(FTPCmd.RNFR, pathname);
}
/***
@@ -1325,7 +1374,7 @@ public class FTP extends SocketClient
***/
public int rnto(String pathname) throws IOException
{
- return sendCommand(FTPCommand.RNTO, pathname);
+ return sendCommand(FTPCmd.RNTO, pathname);
}
/***
@@ -1344,7 +1393,7 @@ public class FTP extends SocketClient
***/
public int dele(String pathname) throws IOException
{
- return sendCommand(FTPCommand.DELE, pathname);
+ return sendCommand(FTPCmd.DELE, pathname);
}
/***
@@ -1363,7 +1412,7 @@ public class FTP extends SocketClient
***/
public int rmd(String pathname) throws IOException
{
- return sendCommand(FTPCommand.RMD, pathname);
+ return sendCommand(FTPCmd.RMD, pathname);
}
/***
@@ -1382,7 +1431,7 @@ public class FTP extends SocketClient
***/
public int mkd(String pathname) throws IOException
{
- return sendCommand(FTPCommand.MKD, pathname);
+ return sendCommand(FTPCmd.MKD, pathname);
}
/***
@@ -1400,7 +1449,7 @@ public class FTP extends SocketClient
***/
public int pwd() throws IOException
{
- return sendCommand(FTPCommand.PWD);
+ return sendCommand(FTPCmd.PWD);
}
/***
@@ -1421,7 +1470,7 @@ public class FTP extends SocketClient
***/
public int list() throws IOException
{
- return sendCommand(FTPCommand.LIST);
+ return sendCommand(FTPCmd.LIST);
}
/***
@@ -1444,7 +1493,7 @@ public class FTP extends SocketClient
***/
public int list(String pathname) throws IOException
{
- return sendCommand(FTPCommand.LIST, pathname);
+ return sendCommand(FTPCmd.LIST, pathname);
}
/**
@@ -1466,7 +1515,7 @@ public class FTP extends SocketClient
*/
public int mlsd() throws IOException
{
- return sendCommand(FTPCommand.MLSD);
+ return sendCommand(FTPCmd.MLSD);
}
/**
@@ -1490,7 +1539,7 @@ public class FTP extends SocketClient
*/
public int mlsd(String path) throws IOException
{
- return sendCommand(FTPCommand.MLSD, path);
+ return sendCommand(FTPCmd.MLSD, path);
}
/**
@@ -1512,7 +1561,7 @@ public class FTP extends SocketClient
*/
public int mlst() throws IOException
{
- return sendCommand(FTPCommand.MLST);
+ return sendCommand(FTPCmd.MLST);
}
/**
@@ -1536,7 +1585,7 @@ public class FTP extends SocketClient
*/
public int mlst(String path) throws IOException
{
- return sendCommand(FTPCommand.MLST, path);
+ return sendCommand(FTPCmd.MLST, path);
}
/***
@@ -1557,7 +1606,7 @@ public class FTP extends SocketClient
***/
public int nlst() throws IOException
{
- return sendCommand(FTPCommand.NLST);
+ return sendCommand(FTPCmd.NLST);
}
/***
@@ -1580,7 +1629,7 @@ public class FTP extends SocketClient
***/
public int nlst(String pathname) throws IOException
{
- return sendCommand(FTPCommand.NLST, pathname);
+ return sendCommand(FTPCmd.NLST, pathname);
}
/***
@@ -1599,7 +1648,7 @@ public class FTP extends SocketClient
***/
public int site(String parameters) throws IOException
{
- return sendCommand(FTPCommand.SITE, parameters);
+ return sendCommand(FTPCmd.SITE, parameters);
}
/***
@@ -1617,7 +1666,7 @@ public class FTP extends SocketClient
***/
public int syst() throws IOException
{
- return sendCommand(FTPCommand.SYST);
+ return sendCommand(FTPCmd.SYST);
}
/***
@@ -1635,7 +1684,7 @@ public class FTP extends SocketClient
***/
public int stat() throws IOException
{
- return sendCommand(FTPCommand.STAT);
+ return sendCommand(FTPCmd.STAT);
}
/***
@@ -1654,7 +1703,7 @@ public class FTP extends SocketClient
***/
public int stat(String pathname) throws IOException
{
- return sendCommand(FTPCommand.STAT, pathname);
+ return sendCommand(FTPCmd.STAT, pathname);
}
/***
@@ -1672,7 +1721,7 @@ public class FTP extends SocketClient
***/
public int help() throws IOException
{
- return sendCommand(FTPCommand.HELP);
+ return sendCommand(FTPCmd.HELP);
}
/***
@@ -1691,7 +1740,7 @@ public class FTP extends SocketClient
***/
public int help(String command) throws IOException
{
- return sendCommand(FTPCommand.HELP, command);
+ return sendCommand(FTPCmd.HELP, command);
}
/***
@@ -1709,7 +1758,7 @@ public class FTP extends SocketClient
***/
public int noop() throws IOException
{
- return sendCommand(FTPCommand.NOOP);
+ return sendCommand(FTPCmd.NOOP);
}
/**
Modified: commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/FTPClient.java
URL: http://svn.apache.org/viewvc/commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/FTPClient.java?rev=1437631&r1=1437630&r2=1437631&view=diff
==============================================================================
--- commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/FTPClient.java (original)
+++ commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/FTPClient.java Wed Jan 23 19:07:10 2013
@@ -608,10 +608,10 @@ implements Configurable
__passivePort = port;
}
- private boolean __storeFile(int command, String remote, InputStream local)
+ private boolean __storeFile(FTPCmd command, String remote, InputStream local)
throws IOException
{
- return _storeFile(FTPCommand.getCommand(command), remote, local);
+ return _storeFile(command.getCommand(), remote, local);
}
/**
@@ -666,10 +666,10 @@ implements Configurable
return ok;
}
- private OutputStream __storeFileStream(int command, String remote)
+ private OutputStream __storeFileStream(FTPCmd command, String remote)
throws IOException
{
- return _storeFileStream(FTPCommand.getCommand(command), remote);
+ return _storeFileStream(command.getCommand(), remote);
}
/**
@@ -719,7 +719,9 @@ implements Configurable
* the connection.
* @exception IOException If an I/O error occurs while either sending a
* command to the server or receiving a reply from the server.
+ * @deprecated Use {@link #_openDataConnection_(FTPCmd, String)} instead
*/
+ @Deprecated
protected Socket _openDataConnection_(int command, String arg)
throws IOException
{
@@ -734,6 +736,30 @@ implements Configurable
* an argument before establishing the data connection. Active
* mode connections also cause a local PORT command to be issued.
* <p>
+ * @param command The int representation of the FTP command to send.
+ * @param arg The arguments to the FTP command. If this parameter is
+ * set to null, then the command is sent with no argument.
+ * @return A Socket corresponding to the established data connection.
+ * Null is returned if an FTP protocol error is reported at
+ * any point during the establishment and initialization of
+ * the connection.
+ * @exception IOException If an I/O error occurs while either sending a
+ * command to the server or receiving a reply from the server.
+ */
+ protected Socket _openDataConnection_(FTPCmd command, String arg)
+ throws IOException
+ {
+ return _openDataConnection_(command.getCommand(), arg);
+ }
+
+ /**
+ * Establishes a data connection with the FTP server, returning
+ * a Socket for the connection if successful. If a restart
+ * offset has been set with {@link #setRestartOffset(long)},
+ * a REST command is issued to the server with the offset as
+ * an argument before establishing the data connection. Active
+ * mode connections also cause a local PORT command to be issued.
+ * <p>
* @param command The text representation of the FTP command to send.
* @param arg The arguments to the FTP command. If this parameter is
* set to null, then the command is sent with no argument.
@@ -1792,7 +1818,7 @@ implements Configurable
public boolean retrieveFile(String remote, OutputStream local)
throws IOException
{
- return _retrieveFile(FTPCommand.getCommand(FTPCommand.RETR), remote, local);
+ return _retrieveFile(FTPCmd.RETR.getCommand(), remote, local);
}
/**
@@ -1867,7 +1893,7 @@ implements Configurable
*/
public InputStream retrieveFileStream(String remote) throws IOException
{
- return _retrieveFileStream(FTPCommand.getCommand(FTPCommand.RETR), remote);
+ return _retrieveFileStream(FTPCmd.RETR.getCommand(), remote);
}
/**
@@ -1926,7 +1952,7 @@ implements Configurable
public boolean storeFile(String remote, InputStream local)
throws IOException
{
- return __storeFile(FTPCommand.STOR, remote, local);
+ return __storeFile(FTPCmd.STOR, remote, local);
}
@@ -1957,7 +1983,7 @@ implements Configurable
*/
public OutputStream storeFileStream(String remote) throws IOException
{
- return __storeFileStream(FTPCommand.STOR, remote);
+ return __storeFileStream(FTPCmd.STOR, remote);
}
/**
@@ -1988,7 +2014,7 @@ implements Configurable
public boolean appendFile(String remote, InputStream local)
throws IOException
{
- return __storeFile(FTPCommand.APPE, remote, local);
+ return __storeFile(FTPCmd.APPE, remote, local);
}
/**
@@ -2018,7 +2044,7 @@ implements Configurable
*/
public OutputStream appendFileStream(String remote) throws IOException
{
- return __storeFileStream(FTPCommand.APPE, remote);
+ return __storeFileStream(FTPCmd.APPE, remote);
}
/**
@@ -2050,7 +2076,7 @@ implements Configurable
public boolean storeUniqueFile(String remote, InputStream local)
throws IOException
{
- return __storeFile(FTPCommand.STOU, remote, local);
+ return __storeFile(FTPCmd.STOU, remote, local);
}
@@ -2083,7 +2109,7 @@ implements Configurable
*/
public OutputStream storeUniqueFileStream(String remote) throws IOException
{
- return __storeFileStream(FTPCommand.STOU, remote);
+ return __storeFileStream(FTPCmd.STOU, remote);
}
/**
@@ -2112,7 +2138,7 @@ implements Configurable
*/
public boolean storeUniqueFile(InputStream local) throws IOException
{
- return __storeFile(FTPCommand.STOU, null, local);
+ return __storeFile(FTPCmd.STOU, null, local);
}
/**
@@ -2142,7 +2168,7 @@ implements Configurable
*/
public OutputStream storeUniqueFileStream() throws IOException
{
- return __storeFileStream(FTPCommand.STOU, null);
+ return __storeFileStream(FTPCmd.STOU, null);
}
/**
@@ -2382,7 +2408,7 @@ implements Configurable
*/
public FTPFile mlistFile(String pathname) throws IOException
{
- boolean success = FTPReply.isPositiveCompletion(sendCommand(FTPCommand.MLST, pathname));
+ boolean success = FTPReply.isPositiveCompletion(sendCommand(FTPCmd.MLST, pathname));
if (success){
String entry = getReplyStrings()[1].substring(1); // skip leading space for parser
return MLSxEntryParser.parseEntry(entry);
@@ -2775,7 +2801,7 @@ implements Configurable
*/
public String[] listNames(String pathname) throws IOException
{
- Socket socket = _openDataConnection_(FTPCommand.NLST, getListArguments(pathname));
+ Socket socket = _openDataConnection_(FTPCmd.NLST, getListArguments(pathname));
if (socket == null) {
return null;
@@ -3243,7 +3269,7 @@ implements Configurable
FTPFileEntryParser parser, String pathname)
throws IOException
{
- Socket socket = _openDataConnection_(FTPCommand.LIST, getListArguments(pathname));
+ Socket socket = _openDataConnection_(FTPCmd.LIST, getListArguments(pathname));
FTPListParseEngine engine = new FTPListParseEngine(parser);
if (socket == null)
@@ -3271,7 +3297,7 @@ implements Configurable
*/
private FTPListParseEngine initiateMListParsing(String pathname) throws IOException
{
- Socket socket = _openDataConnection_(FTPCommand.MLSD, pathname);
+ Socket socket = _openDataConnection_(FTPCmd.MLSD, pathname);
FTPListParseEngine engine = new FTPListParseEngine(MLSxEntryParser.getInstance());
if (socket == null)
{
Added: commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/FTPCmd.java
URL: http://svn.apache.org/viewvc/commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/FTPCmd.java?rev=1437631&view=auto
==============================================================================
--- commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/FTPCmd.java (added)
+++ commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/FTPCmd.java Wed Jan 23 19:07:10 2013
@@ -0,0 +1,113 @@
+/*
+ * 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
+ *
+ * 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;
+
+public enum FTPCmd {
+ ABOR,
+ ACCT,
+ ALLO,
+ APPE,
+ CDUP,
+ CWD,
+ DELE,
+ EPRT,
+ EPSV,
+ FEAT,
+ HELP,
+ LIST,
+ MDTM,
+ MFMT,
+ MKD,
+ MLSD,
+ MLST,
+ MODE,
+ NLST,
+ NOOP,
+ PASS,
+ PASV,
+ PORT,
+ PWD,
+ QUIT,
+ REIN,
+ REST,
+ RETR,
+ RMD,
+ RNFR,
+ RNTO,
+ SITE,
+ SMNT,
+ STAT,
+ STOR,
+ STOU,
+ STRU,
+ SYST,
+ TYPE,
+ USER,
+ ;
+
+ // Aliases
+
+ public static final FTPCmd ABORT = ABOR;
+ public static final FTPCmd ACCOUNT = ACCT;
+ public static final FTPCmd ALLOCATE = ALLO;
+ public static final FTPCmd APPEND = APPE;
+ public static final FTPCmd CHANGE_TO_PARENT_DIRECTORY = CDUP;
+ public static final FTPCmd CHANGE_WORKING_DIRECTORY = CWD;
+ public static final FTPCmd DATA_PORT = PORT;
+ public static final FTPCmd DELETE = DELE;
+ public static final FTPCmd FEATURES = FEAT;
+ public static final FTPCmd FILE_STRUCTURE = STRU;
+ public static final FTPCmd GET_MOD_TIME = MDTM;
+ public static final FTPCmd LOGOUT = QUIT;
+ public static final FTPCmd MAKE_DIRECTORY = MKD;
+ public static final FTPCmd MOD_TIME = MDTM;
+ public static final FTPCmd NAME_LIST = NLST;
+ public static final FTPCmd PASSIVE = PASV;
+ public static final FTPCmd PASSWORD = PASS;
+ public static final FTPCmd PRINT_WORKING_DIRECTORY = PWD;
+ public static final FTPCmd REINITIALIZE = REIN;
+ public static final FTPCmd REMOVE_DIRECTORY = RMD;
+ public static final FTPCmd RENAME_FROM = RNFR;
+ public static final FTPCmd RENAME_TO = RNTO;
+ public static final FTPCmd REPRESENTATION_TYPE = TYPE;
+ public static final FTPCmd RESTART = REST;
+ public static final FTPCmd RETRIEVE = RETR;
+ public static final FTPCmd SET_MOD_TIME = MFMT;
+ public static final FTPCmd SITE_PARAMETERS = SITE;
+ public static final FTPCmd STATUS = STAT;
+ public static final FTPCmd STORE = STOR;
+ public static final FTPCmd STORE_UNIQUE = STOU;
+ public static final FTPCmd STRUCTURE_MOUNT = SMNT;
+ public static final FTPCmd SYSTEM = SYST;
+ public static final FTPCmd TRANSFER_MODE = MODE;
+ public static final FTPCmd USERNAME = USER;
+
+ /**
+ * Retrieve the FTP protocol command string corresponding to a specified
+ * command code.
+ * <p>
+ * @return The FTP protcol command string corresponding to a specified
+ * command code.
+ */
+ public final String getCommand()
+ {
+ return this.name();
+ }
+
+}
Propchange: commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/FTPCmd.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/FTPCmd.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Modified: commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/FTPCommand.java
URL: http://svn.apache.org/viewvc/commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/FTPCommand.java?rev=1437631&r1=1437630&r2=1437631&view=diff
==============================================================================
--- commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/FTPCommand.java (original)
+++ commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/FTPCommand.java Wed Jan 23 19:07:10 2013
@@ -26,8 +26,9 @@ package org.apache.commons.net.ftp;
* where the constant name is the same as the FTP command.
* <p>
* <p>
+ * @deprecated use {@link FTPCmd} instead
*/
-// TODO - replace with an enum?
+@Deprecated
public final class FTPCommand
{
Modified: commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/FTPHTTPClient.java
URL: http://svn.apache.org/viewvc/commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/FTPHTTPClient.java?rev=1437631&r1=1437630&r2=1437631&view=diff
==============================================================================
--- commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/FTPHTTPClient.java (original)
+++ commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/FTPHTTPClient.java Wed Jan 23 19:07:10 2013
@@ -64,10 +64,12 @@ public class FTPHTTPClient extends FTPCl
* {@inheritDoc}
*
* @throws IllegalStateException if connection mode is not passive
+ * @deprecated Use {@link #_openDataConnection_(FTPCmd, String)} instead
*/
// Kept to maintain binary compatibility
// Not strictly necessary, but Clirr complains even though there is a super-impl
@Override
+ @Deprecated
protected Socket _openDataConnection_(int command, String arg)
throws IOException {
return super._openDataConnection_(command, arg);
Modified: commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/FTPSClient.java
URL: http://svn.apache.org/viewvc/commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/FTPSClient.java?rev=1437631&r1=1437630&r2=1437631&view=diff
==============================================================================
--- commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/FTPSClient.java (original)
+++ commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/FTPSClient.java Wed Jan 23 19:07:10 2013
@@ -569,10 +569,12 @@ public class FTPSClient extends FTPClien
* during the establishment and initialization of the connection.
* @throws IOException If there is any problem with the connection.
* @see FTPClient#_openDataConnection_(int, String)
+ * @deprecated Use {@link #_openDataConnection_(FTPCmd, String)} instead
*/
@Override
// Strictly speaking this is not needed, but it works round a Clirr bug
// So rather than invoke the parent code, we do it here
+ @Deprecated
protected Socket _openDataConnection_(int command, String arg)
throws IOException {
return _openDataConnection_(FTPCommand.getCommand(command), arg);
Modified: commons/proper/net/trunk/src/test/java/org/apache/commons/net/ftp/FTPCommandTest.java
URL: http://svn.apache.org/viewvc/commons/proper/net/trunk/src/test/java/org/apache/commons/net/ftp/FTPCommandTest.java?rev=1437631&r1=1437630&r2=1437631&view=diff
==============================================================================
--- commons/proper/net/trunk/src/test/java/org/apache/commons/net/ftp/FTPCommandTest.java (original)
+++ commons/proper/net/trunk/src/test/java/org/apache/commons/net/ftp/FTPCommandTest.java Wed Jan 23 19:07:10 2013
@@ -26,6 +26,7 @@ public class FTPCommandTest extends Test
super(name);
}
+ @SuppressWarnings("deprecation") // test of deprecated code
public void testArray() {
FTPCommand.checkArray();
}
Modified: commons/proper/net/trunk/src/test/java/org/apache/commons/net/ftp/parser/DownloadListings.java
URL: http://svn.apache.org/viewvc/commons/proper/net/trunk/src/test/java/org/apache/commons/net/ftp/parser/DownloadListings.java?rev=1437631&r1=1437630&r2=1437631&view=diff
==============================================================================
--- commons/proper/net/trunk/src/test/java/org/apache/commons/net/ftp/parser/DownloadListings.java (original)
+++ commons/proper/net/trunk/src/test/java/org/apache/commons/net/ftp/parser/DownloadListings.java Wed Jan 23 19:07:10 2013
@@ -32,7 +32,7 @@ import java.net.Socket;
import org.apache.commons.net.PrintCommandListener;
import org.apache.commons.net.ftp.FTPClient;
-import org.apache.commons.net.ftp.FTPCommand;
+import org.apache.commons.net.ftp.FTPCmd;
import org.apache.commons.net.io.Util;
/**
@@ -70,7 +70,7 @@ public class DownloadListings extends FT
removeProtocolCommandListener(listener);
}
- private void download(String path, int command, File filename) throws Exception {
+ private void download(String path, FTPCmd command, File filename) throws Exception {
Socket socket;
if ((socket = _openDataConnection_(command, getListArguments(path))) == null) {
System.out.println(getReplyString());
@@ -114,8 +114,8 @@ public class DownloadListings extends FT
if (self.open(host, port)) {
try {
self.info();
- self.download(path, FTPCommand.LIST, new File(DOWNLOAD_DIR, host+"_list.txt"));
- self.download(path, FTPCommand.MLSD, new File(DOWNLOAD_DIR, host+"_mlsd.txt"));
+ self.download(path, FTPCmd.LIST, new File(DOWNLOAD_DIR, host+"_list.txt"));
+ self.download(path, FTPCmd.MLSD, new File(DOWNLOAD_DIR, host+"_mlsd.txt"));
} catch (Exception e) {
e.printStackTrace();
} finally {