Source Code Cross Referenced for FTP.java in  » Net » Apache-commons-net-1.4.1 » org » apache » commons » net » ftp » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Net » Apache commons net 1.4.1 » org.apache.commons.net.ftp 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*
0002:         * Copyright 2001-2005 The Apache Software Foundation
0003:         *
0004:         * Licensed under the Apache License, Version 2.0 (the "License");
0005:         * you may not use this file except in compliance with the License.
0006:         * You may obtain a copy of the License at
0007:         *
0008:         *     http://www.apache.org/licenses/LICENSE-2.0
0009:         *
0010:         * Unless required by applicable law or agreed to in writing, software
0011:         * distributed under the License is distributed on an "AS IS" BASIS,
0012:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0013:         * See the License for the specific language governing permissions and
0014:         * limitations under the License.
0015:         */
0016:        package org.apache.commons.net.ftp;
0017:
0018:        import java.io.BufferedReader;
0019:        import java.io.BufferedWriter;
0020:        import java.io.IOException;
0021:        import java.io.InputStreamReader;
0022:        import java.io.OutputStreamWriter;
0023:        import java.lang.reflect.InvocationTargetException;
0024:        import java.lang.reflect.Method;
0025:        import java.net.InetAddress;
0026:        import java.net.Socket;
0027:        import java.net.SocketException;
0028:        import java.util.Enumeration;
0029:        import java.util.Vector;
0030:
0031:        import org.apache.commons.net.MalformedServerReplyException;
0032:        import org.apache.commons.net.ProtocolCommandListener;
0033:        import org.apache.commons.net.ProtocolCommandSupport;
0034:        import org.apache.commons.net.SocketClient;
0035:        import org.apache.commons.net.telnet.TelnetClient;
0036:
0037:        /***
0038:         * FTP provides the basic the functionality necessary to implement your
0039:         * own FTP client.  It extends org.apache.commons.net.TelnetClient
0040:         * simply because it saves the writing of extra code to handle the FTP
0041:         * control connection which always remains open during an FTP session and
0042:         * uses the Telnet protocol.  Aggregation would require writing new
0043:         * wrapper methods and wouldn't leverage the functionality already
0044:         * present in org.apache.commons.net.SocketClient.
0045:         * <p>
0046:         * To derive the full benefits of the FTP class requires some knowledge
0047:         * of the FTP protocol defined in RFC 959.  However, there is no reason
0048:         * why you should have to use the FTP class.  The
0049:         * {@link org.apache.commons.net.ftp.FTPClient} class,
0050:         * derived from FTP,
0051:         * implements all the functionality required of an FTP client.  The
0052:         * FTP class is made public to provide access to various FTP constants
0053:         * and to make it easier for adventurous programmers (or those with
0054:         * special needs) to interact with the FTP protocol and implement their
0055:         * own clients.  A set of methods with names corresponding to the FTP
0056:         * command names are provided to facilitate this interaction.
0057:         * <p>
0058:         * You should keep in mind that the FTP server may choose to prematurely
0059:         * close a connection if the client has been idle for longer than a
0060:         * given time period (usually 900 seconds).  The FTP class will detect a
0061:         * premature FTP server connection closing when it receives a
0062:         * {@link org.apache.commons.net.ftp.FTPReply#SERVICE_NOT_AVAILABLE FTPReply.SERVICE_NOT_AVAILABLE }
0063:         *  response to a command.
0064:         * When that occurs, the FTP class method encountering that reply will throw
0065:         * an {@link org.apache.commons.net.ftp.FTPConnectionClosedException}
0066:         * .  <code>FTPConectionClosedException</code>
0067:         * is a subclass of <code> IOException </code> and therefore need not be
0068:         * caught separately, but if you are going to catch it separately, its
0069:         * catch block must appear before the more general <code> IOException </code>
0070:         * catch block.  When you encounter an
0071:         * {@link org.apache.commons.net.ftp.FTPConnectionClosedException}
0072:         * , you must disconnect the connection with
0073:         * {@link #disconnect  disconnect() } to properly clean up the
0074:         * system resources used by FTP.  Before disconnecting, you may check the
0075:         * last reply code and text with
0076:         * {@link #getReplyCode  getReplyCode },
0077:         * {@link #getReplyString  getReplyString },
0078:         * and {@link #getReplyStrings  getReplyStrings}.
0079:         * You may avoid server disconnections while the client is idle by
0080:         * periodicaly sending NOOP commands to the server.
0081:         * <p>
0082:         * Rather than list it separately for each method, we mention here that
0083:         * every method communicating with the server and throwing an IOException
0084:         * can also throw a
0085:         * {@link org.apache.commons.net.MalformedServerReplyException}
0086:         * , which is a subclass
0087:         * of IOException.  A MalformedServerReplyException will be thrown when
0088:         * the reply received from the server deviates enough from the protocol
0089:         * specification that it cannot be interpreted in a useful manner despite
0090:         * attempts to be as lenient as possible.
0091:         * <p>
0092:         * <p>
0093:         * @author Daniel F. Savarese
0094:         * @see FTPClient
0095:         * @see FTPConnectionClosedException
0096:         * @see org.apache.commons.net.MalformedServerReplyException
0097:         ***/
0098:
0099:        public class FTP extends TelnetClient {
0100:            /*** The default FTP data port (20). ***/
0101:            public static final int DEFAULT_DATA_PORT = 20;
0102:            /*** The default FTP control port (21). ***/
0103:            public static final int DEFAULT_PORT = 21;
0104:
0105:            /***
0106:             * A constant used to indicate the file(s) being transfered should
0107:             * be treated as ASCII.  This is the default file type.  All constants
0108:             * ending in <code>FILE_TYPE</code> are used to indicate file types.
0109:             ***/
0110:            public static final int ASCII_FILE_TYPE = 0;
0111:
0112:            /***
0113:             * A constant used to indicate the file(s) being transfered should
0114:             * be treated as EBCDIC.  Note however that there are several different
0115:             * EBCDIC formats.  All constants ending in <code>FILE_TYPE</code>
0116:             * are used to indicate file types.
0117:             ***/
0118:            public static final int EBCDIC_FILE_TYPE = 1;
0119:
0120:            /***
0121:             * A constant used to indicate the file(s) being transfered should
0122:             * be treated as a binary image, i.e., no translations should be
0123:             * performed.  All constants ending in <code>FILE_TYPE</code> are used to
0124:             * indicate file types.
0125:             ***/
0126:            public static final int IMAGE_FILE_TYPE = 2;
0127:
0128:            /***
0129:             * A constant used to indicate the file(s) being transfered should
0130:             * be treated as a binary image, i.e., no translations should be
0131:             * performed.  All constants ending in <code>FILE_TYPE</code> are used to
0132:             * indicate file types.
0133:             ***/
0134:            public static final int BINARY_FILE_TYPE = 2;
0135:
0136:            /***
0137:             * A constant used to indicate the file(s) being transfered should
0138:             * be treated as a local type.  All constants ending in
0139:             * <code>FILE_TYPE</code> are used to indicate file types.
0140:             ***/
0141:            public static final int LOCAL_FILE_TYPE = 3;
0142:
0143:            /***
0144:             * A constant used for text files to indicate a non-print text format.
0145:             * This is the default format.
0146:             * All constants ending in <code>TEXT_FORMAT</code> are used to indicate
0147:             * text formatting for text transfers (both ASCII and EBCDIC).
0148:             ***/
0149:            public static final int NON_PRINT_TEXT_FORMAT = 4;
0150:
0151:            /***
0152:             * A constant used to indicate a text file contains format vertical format
0153:             * control characters.
0154:             * All constants ending in <code>TEXT_FORMAT</code> are used to indicate
0155:             * text formatting for text transfers (both ASCII and EBCDIC).
0156:             ***/
0157:            public static final int TELNET_TEXT_FORMAT = 5;
0158:
0159:            /***
0160:             * A constant used to indicate a text file contains ASA vertical format
0161:             * control characters.
0162:             * All constants ending in <code>TEXT_FORMAT</code> are used to indicate
0163:             * text formatting for text transfers (both ASCII and EBCDIC).
0164:             ***/
0165:            public static final int CARRIAGE_CONTROL_TEXT_FORMAT = 6;
0166:
0167:            /***
0168:             * A constant used to indicate a file is to be treated as a continuous
0169:             * sequence of bytes.  This is the default structure.  All constants ending
0170:             * in <code>_STRUCTURE</code> are used to indicate file structure for
0171:             * file transfers.
0172:             ***/
0173:            public static final int FILE_STRUCTURE = 7;
0174:
0175:            /***
0176:             * A constant used to indicate a file is to be treated as a sequence
0177:             * of records.  All constants ending in <code>_STRUCTURE</code>
0178:             * are used to indicate file structure for file transfers.
0179:             ***/
0180:            public static final int RECORD_STRUCTURE = 8;
0181:
0182:            /***
0183:             * A constant used to indicate a file is to be treated as a set of
0184:             * independent indexed pages.  All constants ending in
0185:             * <code>_STRUCTURE</code> are used to indicate file structure for file
0186:             * transfers.
0187:             ***/
0188:            public static final int PAGE_STRUCTURE = 9;
0189:
0190:            /***
0191:             * A constant used to indicate a file is to be transfered as a stream
0192:             * of bytes.  This is the default transfer mode.  All constants ending
0193:             * in <code>TRANSFER_MODE</code> are used to indicate file transfer
0194:             * modes.
0195:             ***/
0196:            public static final int STREAM_TRANSFER_MODE = 10;
0197:
0198:            /***
0199:             * A constant used to indicate a file is to be transfered as a series
0200:             * of blocks.  All constants ending in <code>TRANSFER_MODE</code> are used
0201:             * to indicate file transfer modes.
0202:             ***/
0203:            public static final int BLOCK_TRANSFER_MODE = 11;
0204:
0205:            /***
0206:             * A constant used to indicate a file is to be transfered as FTP
0207:             * compressed data.  All constants ending in <code>TRANSFER_MODE</code>
0208:             * are used to indicate file transfer modes.
0209:             ***/
0210:            public static final int COMPRESSED_TRANSFER_MODE = 12;
0211:
0212:            // We have to ensure that the protocol communication is in ASCII
0213:            // but we use ISO-8859-1 just in case 8-bit characters cross
0214:            // the wire.
0215:            /**
0216:             * The default character encoding used for communicating over an
0217:             * FTP control connection.  The default encoding is an
0218:             * ASCII-compatible encoding.  Some FTP servers expect other
0219:             * encodings.  You can change the encoding used by an FTP instance
0220:             * with {@link #setControlEncoding setControlEncoding}.
0221:             */
0222:            public static final String DEFAULT_CONTROL_ENCODING = "ISO-8859-1";
0223:            private static final String __modes = "ABILNTCFRPSBC";
0224:
0225:            private StringBuffer __commandBuffer;
0226:
0227:            BufferedReader _controlInput;
0228:            BufferedWriter _controlOutput;
0229:            int _replyCode;
0230:            Vector _replyLines;
0231:            boolean _newReplyString;
0232:            String _replyString;
0233:            String _controlEncoding;
0234:
0235:            /***
0236:             * A ProtocolCommandSupport object used to manage the registering of
0237:             * ProtocolCommandListeners and te firing of ProtocolCommandEvents.
0238:             ***/
0239:            protected ProtocolCommandSupport _commandSupport_;
0240:
0241:            /***
0242:             * The default FTP constructor.  Sets the default port to
0243:             * <code>DEFAULT_PORT</code> and initializes internal data structures
0244:             * for saving FTP reply information.
0245:             ***/
0246:            public FTP() {
0247:                setDefaultPort(DEFAULT_PORT);
0248:                __commandBuffer = new StringBuffer();
0249:                _replyLines = new Vector();
0250:                _newReplyString = false;
0251:                _replyString = null;
0252:                _commandSupport_ = new ProtocolCommandSupport(this );
0253:                _controlEncoding = DEFAULT_CONTROL_ENCODING;
0254:            }
0255:
0256:            private void __getReply() throws IOException {
0257:                int length;
0258:
0259:                _newReplyString = true;
0260:                _replyLines.setSize(0);
0261:
0262:                String line = _controlInput.readLine();
0263:
0264:                if (line == null)
0265:                    throw new FTPConnectionClosedException(
0266:                            "Connection closed without indication.");
0267:
0268:                // In case we run into an anomaly we don't want fatal index exceptions
0269:                // to be thrown.
0270:                length = line.length();
0271:                if (length < 3)
0272:                    throw new MalformedServerReplyException(
0273:                            "Truncated server reply: " + line);
0274:
0275:                try {
0276:                    String code = line.substring(0, 3);
0277:                    _replyCode = Integer.parseInt(code);
0278:                } catch (NumberFormatException e) {
0279:                    throw new MalformedServerReplyException(
0280:                            "Could not parse response code.\nServer Reply: "
0281:                                    + line);
0282:                }
0283:
0284:                _replyLines.addElement(line);
0285:
0286:                // Get extra lines if message continues.
0287:                if (length > 3 && line.charAt(3) == '-') {
0288:                    do {
0289:                        line = _controlInput.readLine();
0290:
0291:                        if (line == null)
0292:                            throw new FTPConnectionClosedException(
0293:                                    "Connection closed without indication.");
0294:
0295:                        _replyLines.addElement(line);
0296:
0297:                        // The length() check handles problems that could arise from readLine()
0298:                        // returning too soon after encountering a naked CR or some other
0299:                        // anomaly.
0300:                    } while (!(line.length() >= 4 && line.charAt(3) != '-' && Character
0301:                            .isDigit(line.charAt(0))));
0302:                    // This is too strong a condition because of non-conforming ftp
0303:                    // servers like ftp.funet.fi which sent 226 as the last line of a
0304:                    // 426 multi-line reply in response to ls /.  We relax the condition to
0305:                    // test that the line starts with a digit rather than starting with
0306:                    // the code.
0307:                    // line.startsWith(code)));
0308:                }
0309:
0310:                if (_commandSupport_.getListenerCount() > 0)
0311:                    _commandSupport_.fireReplyReceived(_replyCode,
0312:                            getReplyString());
0313:
0314:                if (_replyCode == FTPReply.SERVICE_NOT_AVAILABLE)
0315:                    throw new FTPConnectionClosedException(
0316:                            "FTP response 421 received.  Server closed connection.");
0317:            }
0318:
0319:            // initiates control connections and gets initial reply
0320:            protected void _connectAction_() throws IOException {
0321:                super ._connectAction_();
0322:                _controlInput = new BufferedReader(new InputStreamReader(
0323:                        getInputStream(), getControlEncoding()));
0324:                _controlOutput = new BufferedWriter(new OutputStreamWriter(
0325:                        getOutputStream(), getControlEncoding()));
0326:                __getReply();
0327:                // If we received code 120, we have to fetch completion reply.
0328:                if (FTPReply.isPositivePreliminary(_replyCode))
0329:                    __getReply();
0330:            }
0331:
0332:            /**
0333:             * Sets the character encoding used by the FTP control connection.
0334:             * Some FTP servers require that commands be issued in a non-ASCII
0335:             * encoding like UTF-8 so that filenames with multi-byte character
0336:             * representations (e.g, Big 8) can be specified.
0337:             *
0338:             * @param encoding The new character encoding for the control connection.
0339:             */
0340:            public void setControlEncoding(String encoding) {
0341:                _controlEncoding = encoding;
0342:            }
0343:
0344:            /**
0345:             * @return The character encoding used to communicate over the
0346:             * control connection.
0347:             */
0348:            public String getControlEncoding() {
0349:                return _controlEncoding;
0350:            }
0351:
0352:            /***
0353:             * Adds a ProtocolCommandListener.  Delegates this task to
0354:             * {@link #_commandSupport_  _commandSupport_ }.
0355:             * <p>
0356:             * @param listener  The ProtocolCommandListener to add.
0357:             ***/
0358:            public void addProtocolCommandListener(
0359:                    ProtocolCommandListener listener) {
0360:                _commandSupport_.addProtocolCommandListener(listener);
0361:            }
0362:
0363:            /***
0364:             * Removes a ProtocolCommandListener.  Delegates this task to
0365:             * {@link #_commandSupport_  _commandSupport_ }.
0366:             * <p>
0367:             * @param listener  The ProtocolCommandListener to remove.
0368:             ***/
0369:            public void removeProtocolCommandListener(
0370:                    ProtocolCommandListener listener) {
0371:                _commandSupport_.removeProtocolCommandListener(listener);
0372:            }
0373:
0374:            /***
0375:             * Closes the control connection to the FTP server and sets to null
0376:             * some internal data so that the memory may be reclaimed by the
0377:             * garbage collector.  The reply text and code information from the
0378:             * last command is voided so that the memory it used may be reclaimed.
0379:             * <p>
0380:             * @exception IOException If an error occurs while disconnecting.
0381:             ***/
0382:            public void disconnect() throws IOException {
0383:                super .disconnect();
0384:                _controlInput = null;
0385:                _controlOutput = null;
0386:                _replyLines.setSize(0);
0387:                _newReplyString = false;
0388:                _replyString = null;
0389:            }
0390:
0391:            /***
0392:             * Sends an FTP command to the server, waits for a reply and returns the
0393:             * numerical response code.  After invocation, for more detailed
0394:             * information, the actual reply text can be accessed by calling
0395:             * {@link #getReplyString  getReplyString } or
0396:             * {@link #getReplyStrings  getReplyStrings }.
0397:             * <p>
0398:             * @param command  The text representation of the  FTP command to send.
0399:             * @param args The arguments to the FTP command.  If this parameter is
0400:             *             set to null, then the command is sent with no argument.
0401:             * @return The integer value of the FTP reply code returned by the server
0402:             *         in response to the command.
0403:             * @exception FTPConnectionClosedException
0404:             *      If the FTP server prematurely closes the connection as a result
0405:             *      of the client being idle or some other reason causing the server
0406:             *      to send FTP reply code 421.  This exception may be caught either
0407:             *      as an IOException or independently as itself.
0408:             * @exception IOException  If an I/O error occurs while either sending the
0409:             *      command or receiving the server reply.
0410:             ***/
0411:            public int sendCommand(String command, String args)
0412:                    throws IOException {
0413:                String message;
0414:
0415:                __commandBuffer.setLength(0);
0416:                __commandBuffer.append(command);
0417:
0418:                if (args != null) {
0419:                    __commandBuffer.append(' ');
0420:                    __commandBuffer.append(args);
0421:                }
0422:                __commandBuffer.append(SocketClient.NETASCII_EOL);
0423:
0424:                try {
0425:                    _controlOutput.write(message = __commandBuffer.toString());
0426:                    _controlOutput.flush();
0427:                } catch (SocketException e) {
0428:                    if (!isConnected() || !socketIsConnected(_socket_)) {
0429:                        throw new FTPConnectionClosedException(
0430:                                "Connection unexpectedly closed.");
0431:                    } else {
0432:                        throw e;
0433:                    }
0434:                }
0435:
0436:                if (_commandSupport_.getListenerCount() > 0)
0437:                    _commandSupport_.fireCommandSent(command, message);
0438:
0439:                __getReply();
0440:                return _replyCode;
0441:            }
0442:
0443:            /**
0444:             * Checks if the socket is connected using reflection to be backward compatible.
0445:             * The return value of this method is only meaningful in an java 1.4 environment.
0446:             *
0447:             * @param socket
0448:             * @return true if connected or pre java 1.4
0449:             */
0450:            private boolean socketIsConnected(Socket socket) {
0451:                if (socket == null) {
0452:                    return false;
0453:                }
0454:
0455:                try {
0456:                    Method isConnected = socket.getClass().getMethod(
0457:                            "isConnected", null);
0458:                    return ((Boolean) isConnected.invoke(socket, null))
0459:                            .booleanValue();
0460:                } catch (NoSuchMethodException e) {
0461:                    return true;
0462:                } catch (IllegalAccessException e) {
0463:                    return true;
0464:                } catch (InvocationTargetException e) {
0465:                    return true;
0466:                }
0467:            }
0468:
0469:            /***
0470:             * Sends an FTP command to the server, waits for a reply and returns the
0471:             * numerical response code.  After invocation, for more detailed
0472:             * information, the actual reply text can be accessed by calling
0473:             * {@link #getReplyString  getReplyString } or
0474:             * {@link #getReplyStrings  getReplyStrings }.
0475:             * <p>
0476:             * @param command  The FTPCommand constant corresponding to the FTP command
0477:             *                 to send.
0478:             * @param args The arguments to the FTP command.  If this parameter is
0479:             *             set to null, then the command is sent with no argument.
0480:             * @return The integer value of the FTP reply code returned by the server
0481:             *         in response to the command.
0482:             * @exception FTPConnectionClosedException
0483:             *      If the FTP server prematurely closes the connection as a result
0484:             *      of the client being idle or some other reason causing the server
0485:             *      to send FTP reply code 421.  This exception may be caught either
0486:             *      as an IOException or independently as itself.
0487:             * @exception IOException  If an I/O error occurs while either sending the
0488:             *      command or receiving the server reply.
0489:             ***/
0490:            public int sendCommand(int command, String args) throws IOException {
0491:                return sendCommand(FTPCommand._commands[command], args);
0492:            }
0493:
0494:            /***
0495:             * Sends an FTP command with no arguments to the server, waits for a
0496:             * reply and returns the numerical response code.  After invocation, for
0497:             * more detailed information, the actual reply text can be accessed by
0498:             * calling {@link #getReplyString  getReplyString } or
0499:             * {@link #getReplyStrings  getReplyStrings }.
0500:             * <p>
0501:             * @param command  The text representation of the  FTP command to send.
0502:             * @return The integer value of the FTP reply code returned by the server
0503:             *         in response to the command.
0504:             * @exception FTPConnectionClosedException
0505:             *      If the FTP server prematurely closes the connection as a result
0506:             *      of the client being idle or some other reason causing the server
0507:             *      to send FTP reply code 421.  This exception may be caught either
0508:             *      as an IOException or independently as itself.
0509:             * @exception IOException  If an I/O error occurs while either sending the
0510:             *      command or receiving the server reply.
0511:             ***/
0512:            public int sendCommand(String command) throws IOException {
0513:                return sendCommand(command, null);
0514:            }
0515:
0516:            /***
0517:             * Sends an FTP command with no arguments to the server, waits for a
0518:             * reply and returns the numerical response code.  After invocation, for
0519:             * more detailed information, the actual reply text can be accessed by
0520:             * calling {@link #getReplyString  getReplyString } or
0521:             * {@link #getReplyStrings  getReplyStrings }.
0522:             * <p>
0523:             * @param command  The FTPCommand constant corresponding to the FTP command
0524:             *                 to send.
0525:             * @return The integer value of the FTP reply code returned by the server
0526:             *         in response to the command.
0527:             * @exception FTPConnectionClosedException
0528:             *      If the FTP server prematurely closes the connection as a result
0529:             *      of the client being idle or some other reason causing the server
0530:             *      to send FTP reply code 421.  This exception may be caught either
0531:             *      as an IOException or independently as itself.
0532:             * @exception IOException  If an I/O error occurs while either sending the
0533:             *      command or receiving the server reply.
0534:             ***/
0535:            public int sendCommand(int command) throws IOException {
0536:                return sendCommand(command, null);
0537:            }
0538:
0539:            /***
0540:             * Returns the integer value of the reply code of the last FTP reply.
0541:             * You will usually only use this method after you connect to the
0542:             * FTP server to check that the connection was successful since
0543:             * <code> connect </code> is of type void.
0544:             * <p>
0545:             * @return The integer value of the reply code of the last FTP reply.
0546:             ***/
0547:            public int getReplyCode() {
0548:                return _replyCode;
0549:            }
0550:
0551:            /***
0552:             * Fetches a reply from the FTP server and returns the integer reply
0553:             * code.  After calling this method, the actual reply text can be accessed
0554:             * from either  calling {@link #getReplyString  getReplyString } or
0555:             * {@link #getReplyStrings  getReplyStrings }.  Only use this
0556:             * method if you are implementing your own FTP client or if you need to
0557:             * fetch a secondary response from the FTP server.
0558:             * <p>
0559:             * @return The integer value of the reply code of the fetched FTP reply.
0560:             * @exception FTPConnectionClosedException
0561:             *      If the FTP server prematurely closes the connection as a result
0562:             *      of the client being idle or some other reason causing the server
0563:             *      to send FTP reply code 421.  This exception may be caught either
0564:             *      as an IOException or independently as itself.
0565:             * @exception IOException  If an I/O error occurs while receiving the
0566:             *                         server reply.
0567:             ***/
0568:            public int getReply() throws IOException {
0569:                __getReply();
0570:                return _replyCode;
0571:            }
0572:
0573:            /***
0574:             * Returns the lines of text from the last FTP server response as an array
0575:             * of strings, one entry per line.  The end of line markers of each are
0576:             * stripped from each line.
0577:             * <p>
0578:             * @return The lines of text from the last FTP response as an array.
0579:             ***/
0580:            public String[] getReplyStrings() {
0581:                String[] lines;
0582:                lines = new String[_replyLines.size()];
0583:                _replyLines.copyInto(lines);
0584:                return lines;
0585:            }
0586:
0587:            /***
0588:             * Returns the entire text of the last FTP server response exactly
0589:             * as it was received, including all end of line markers in NETASCII
0590:             * format.
0591:             * <p>
0592:             * @return The entire text from the last FTP response as a String.
0593:             ***/
0594:            public String getReplyString() {
0595:                Enumeration en;
0596:                StringBuffer buffer;
0597:
0598:                if (!_newReplyString)
0599:                    return _replyString;
0600:
0601:                buffer = new StringBuffer(256);
0602:                en = _replyLines.elements();
0603:                while (en.hasMoreElements()) {
0604:                    buffer.append((String) en.nextElement());
0605:                    buffer.append(SocketClient.NETASCII_EOL);
0606:                }
0607:
0608:                _newReplyString = false;
0609:
0610:                return (_replyString = buffer.toString());
0611:            }
0612:
0613:            /***
0614:             * A convenience method to send the FTP USER command to the server,
0615:             * receive the reply, and return the reply code.
0616:             * <p>
0617:             * @param username  The username to login under.
0618:             * @return The reply code received from the server.
0619:             * @exception FTPConnectionClosedException
0620:             *      If the FTP server prematurely closes the connection as a result
0621:             *      of the client being idle or some other reason causing the server
0622:             *      to send FTP reply code 421.  This exception may be caught either
0623:             *      as an IOException or independently as itself.
0624:             * @exception IOException  If an I/O error occurs while either sending the
0625:             *      command or receiving the server reply.
0626:             ***/
0627:            public int user(String username) throws IOException {
0628:                return sendCommand(FTPCommand.USER, username);
0629:            }
0630:
0631:            /**
0632:             * A convenience method to send the FTP PASS command to the server,
0633:             * receive the reply, and return the reply code.
0634:             * @param password The plain text password of the username being logged into.
0635:             * @return The reply code received from the server.
0636:             * @exception FTPConnectionClosedException
0637:             *      If the FTP server prematurely closes the connection as a result
0638:             *      of the client being idle or some other reason causing the server
0639:             *      to send FTP reply code 421.  This exception may be caught either
0640:             *      as an IOException or independently as itself.
0641:             * @exception IOException  If an I/O error occurs while either sending the
0642:             *      command or receiving the server reply.
0643:             */
0644:            public int pass(String password) throws IOException {
0645:                return sendCommand(FTPCommand.PASS, password);
0646:            }
0647:
0648:            /***
0649:             * A convenience method to send the FTP ACCT command to the server,
0650:             * receive the reply, and return the reply code.
0651:             * <p>
0652:             * @param account  The account name to access.
0653:             * @return The reply code received from the server.
0654:             * @exception FTPConnectionClosedException
0655:             *      If the FTP server prematurely closes the connection as a result
0656:             *      of the client being idle or some other reason causing the server
0657:             *      to send FTP reply code 421.  This exception may be caught either
0658:             *      as an IOException or independently as itself.
0659:             * @exception IOException  If an I/O error occurs while either sending the
0660:             *      command or receiving the server reply.
0661:             ***/
0662:            public int acct(String account) throws IOException {
0663:                return sendCommand(FTPCommand.ACCT, account);
0664:            }
0665:
0666:            /***
0667:             * A convenience method to send the FTP ABOR command to the server,
0668:             * receive the reply, and return the reply code.
0669:             * <p>
0670:             * @return The reply code received from the server.
0671:             * @exception FTPConnectionClosedException
0672:             *      If the FTP server prematurely closes the connection as a result
0673:             *      of the client being idle or some other reason causing the server
0674:             *      to send FTP reply code 421.  This exception may be caught either
0675:             *      as an IOException or independently as itself.
0676:             * @exception IOException  If an I/O error occurs while either sending the
0677:             *      command or receiving the server reply.
0678:             ***/
0679:            public int abor() throws IOException {
0680:                return sendCommand(FTPCommand.ABOR);
0681:            }
0682:
0683:            /***
0684:             * A convenience method to send the FTP CWD command to the server,
0685:             * receive the reply, and return the reply code.
0686:             * <p>
0687:             * @param directory The new working directory.
0688:             * @return The reply code received from the server.
0689:             * @exception FTPConnectionClosedException
0690:             *      If the FTP server prematurely closes the connection as a result
0691:             *      of the client being idle or some other reason causing the server
0692:             *      to send FTP reply code 421.  This exception may be caught either
0693:             *      as an IOException or independently as itself.
0694:             * @exception IOException  If an I/O error occurs while either sending the
0695:             *      command or receiving the server reply.
0696:             ***/
0697:            public int cwd(String directory) throws IOException {
0698:                return sendCommand(FTPCommand.CWD, directory);
0699:            }
0700:
0701:            /***
0702:             * A convenience method to send the FTP CDUP command to the server,
0703:             * receive the reply, and return the reply code.
0704:             * <p>
0705:             * @return The reply code received from the server.
0706:             * @exception FTPConnectionClosedException
0707:             *      If the FTP server prematurely closes the connection as a result
0708:             *      of the client being idle or some other reason causing the server
0709:             *      to send FTP reply code 421.  This exception may be caught either
0710:             *      as an IOException or independently as itself.
0711:             * @exception IOException  If an I/O error occurs while either sending the
0712:             *      command or receiving the server reply.
0713:             ***/
0714:            public int cdup() throws IOException {
0715:                return sendCommand(FTPCommand.CDUP);
0716:            }
0717:
0718:            /***
0719:             * A convenience method to send the FTP QUIT command to the server,
0720:             * receive the reply, and return the reply code.
0721:             * <p>
0722:             * @return The reply code received from the server.
0723:             * @exception FTPConnectionClosedException
0724:             *      If the FTP server prematurely closes the connection as a result
0725:             *      of the client being idle or some other reason causing the server
0726:             *      to send FTP reply code 421.  This exception may be caught either
0727:             *      as an IOException or independently as itself.
0728:             * @exception IOException  If an I/O error occurs while either sending the
0729:             *      command or receiving the server reply.
0730:             ***/
0731:            public int quit() throws IOException {
0732:                return sendCommand(FTPCommand.QUIT);
0733:            }
0734:
0735:            /***
0736:             * A convenience method to send the FTP REIN command to the server,
0737:             * receive the reply, and return the reply code.
0738:             * <p>
0739:             * @return The reply code received from the server.
0740:             * @exception FTPConnectionClosedException
0741:             *      If the FTP server prematurely closes the connection as a result
0742:             *      of the client being idle or some other reason causing the server
0743:             *      to send FTP reply code 421.  This exception may be caught either
0744:             *      as an IOException or independently as itself.
0745:             * @exception IOException  If an I/O error occurs while either sending the
0746:             *      command or receiving the server reply.
0747:             ***/
0748:            public int rein() throws IOException {
0749:                return sendCommand(FTPCommand.REIN);
0750:            }
0751:
0752:            /***
0753:             * A convenience method to send the FTP SMNT command to the server,
0754:             * receive the reply, and return the reply code.
0755:             * <p>
0756:             * @param dir  The directory name.
0757:             * @return The reply code received from the server.
0758:             * @exception FTPConnectionClosedException
0759:             *      If the FTP server prematurely closes the connection as a result
0760:             *      of the client being idle or some other reason causing the server
0761:             *      to send FTP reply code 421.  This exception may be caught either
0762:             *      as an IOException or independently as itself.
0763:             * @exception IOException  If an I/O error occurs while either sending the
0764:             *      command or receiving the server reply.
0765:             ***/
0766:            public int smnt(String dir) throws IOException {
0767:                return sendCommand(FTPCommand.SMNT, dir);
0768:            }
0769:
0770:            /***
0771:             * A convenience method to send the FTP PORT command to the server,
0772:             * receive the reply, and return the reply code.
0773:             * <p>
0774:             * @param host  The host owning the port.
0775:             * @param port  The new port.
0776:             * @return The reply code received from the server.
0777:             * @exception FTPConnectionClosedException
0778:             *      If the FTP server prematurely closes the connection as a result
0779:             *      of the client being idle or some other reason causing the server
0780:             *      to send FTP reply code 421.  This exception may be caught either
0781:             *      as an IOException or independently as itself.
0782:             * @exception IOException  If an I/O error occurs while either sending the
0783:             *      command or receiving the server reply.
0784:             ***/
0785:            public int port(InetAddress host, int port) throws IOException {
0786:                int num;
0787:                StringBuffer info = new StringBuffer(24);
0788:
0789:                info.append(host.getHostAddress().replace('.', ','));
0790:                num = port >>> 8;
0791:                info.append(',');
0792:                info.append(num);
0793:                info.append(',');
0794:                num = port & 0xff;
0795:                info.append(num);
0796:
0797:                return sendCommand(FTPCommand.PORT, info.toString());
0798:            }
0799:
0800:            /***
0801:             * A convenience method to send the FTP PASV command to the server,
0802:             * receive the reply, and return the reply code.  Remember, it's up
0803:             * to you to interpret the reply string containing the host/port
0804:             * information.
0805:             * <p>
0806:             * @return The reply code received from the server.
0807:             * @exception FTPConnectionClosedException
0808:             *      If the FTP server prematurely closes the connection as a result
0809:             *      of the client being idle or some other reason causing the server
0810:             *      to send FTP reply code 421.  This exception may be caught either
0811:             *      as an IOException or independently as itself.
0812:             * @exception IOException  If an I/O error occurs while either sending the
0813:             *      command or receiving the server reply.
0814:             ***/
0815:            public int pasv() throws IOException {
0816:                return sendCommand(FTPCommand.PASV);
0817:            }
0818:
0819:            /**
0820:             * A convenience method to send the FTP TYPE command for text files
0821:             * to the server, receive the reply, and return the reply code.
0822:             * @param fileType  The type of the file (one of the <code>FILE_TYPE</code>
0823:             *              constants).
0824:             * @param formatOrByteSize  The format of the file (one of the
0825:             *              <code>_FORMAT</code> constants.  In the case of
0826:             *              <code>LOCAL_FILE_TYPE</code>, the byte size.
0827:             * @return The reply code received from the server.
0828:             * @exception FTPConnectionClosedException
0829:             *      If the FTP server prematurely closes the connection as a result
0830:             *      of the client being idle or some other reason causing the server
0831:             *      to send FTP reply code 421.  This exception may be caught either
0832:             *      as an IOException or independently as itself.
0833:             * @exception IOException  If an I/O error occurs while either sending the
0834:             *      command or receiving the server reply.
0835:             */
0836:            public int type(int fileType, int formatOrByteSize)
0837:                    throws IOException {
0838:                StringBuffer arg = new StringBuffer();
0839:
0840:                arg.append(__modes.charAt(fileType));
0841:                arg.append(' ');
0842:                if (fileType == LOCAL_FILE_TYPE)
0843:                    arg.append(formatOrByteSize);
0844:                else
0845:                    arg.append(__modes.charAt(formatOrByteSize));
0846:
0847:                return sendCommand(FTPCommand.TYPE, arg.toString());
0848:            }
0849:
0850:            /**
0851:             * A convenience method to send the FTP TYPE command to the server,
0852:             * receive the reply, and return the reply code.
0853:             * <p>
0854:             * @param fileType  The type of the file (one of the <code>FILE_TYPE</code>
0855:             *              constants).
0856:             * @return The reply code received from the server.
0857:             * @exception FTPConnectionClosedException
0858:             *      If the FTP server prematurely closes the connection as a result
0859:             *      of the client being idle or some other reason causing the server
0860:             *      to send FTP reply code 421.  This exception may be caught either
0861:             *      as an IOException or independently as itself.
0862:             * @exception IOException  If an I/O error occurs while either sending the
0863:             *      command or receiving the server reply.
0864:             */
0865:            public int type(int fileType) throws IOException {
0866:                return sendCommand(FTPCommand.TYPE, __modes.substring(fileType,
0867:                        fileType + 1));
0868:            }
0869:
0870:            /***
0871:             * A convenience method to send the FTP STRU command to the server,
0872:             * receive the reply, and return the reply code.
0873:             * <p>
0874:             * @param structure  The structure of the file (one of the
0875:             *         <code>_STRUCTURE</code> constants).
0876:             * @return The reply code received from the server.
0877:             * @exception FTPConnectionClosedException
0878:             *      If the FTP server prematurely closes the connection as a result
0879:             *      of the client being idle or some other reason causing the server
0880:             *      to send FTP reply code 421.  This exception may be caught either
0881:             *      as an IOException or independently as itself.
0882:             * @exception IOException  If an I/O error occurs while either sending the
0883:             *      command or receiving the server reply.
0884:             ***/
0885:            public int stru(int structure) throws IOException {
0886:                return sendCommand(FTPCommand.STRU, __modes.substring(
0887:                        structure, structure + 1));
0888:            }
0889:
0890:            /***
0891:             * A convenience method to send the FTP MODE command to the server,
0892:             * receive the reply, and return the reply code.
0893:             * <p>
0894:             * @param mode  The transfer mode to use (one of the
0895:             *         <code>TRANSFER_MODE</code> constants).
0896:             * @return The reply code received from the server.
0897:             * @exception FTPConnectionClosedException
0898:             *      If the FTP server prematurely closes the connection as a result
0899:             *      of the client being idle or some other reason causing the server
0900:             *      to send FTP reply code 421.  This exception may be caught either
0901:             *      as an IOException or independently as itself.
0902:             * @exception IOException  If an I/O error occurs while either sending the
0903:             *      command or receiving the server reply.
0904:             ***/
0905:            public int mode(int mode) throws IOException {
0906:                return sendCommand(FTPCommand.MODE, __modes.substring(mode,
0907:                        mode + 1));
0908:            }
0909:
0910:            /***
0911:             * A convenience method to send the FTP RETR command to the server,
0912:             * receive the reply, and return the reply code.  Remember, it is up
0913:             * to you to manage the data connection.  If you don't need this low
0914:             * level of access, use {@link org.apache.commons.net.ftp.FTPClient}
0915:             * , which will handle all low level details for you.
0916:             * <p>
0917:             * @param pathname  The pathname of the file to retrieve.
0918:             * @return The reply code received from the server.
0919:             * @exception FTPConnectionClosedException
0920:             *      If the FTP server prematurely closes the connection as a result
0921:             *      of the client being idle or some other reason causing the server
0922:             *      to send FTP reply code 421.  This exception may be caught either
0923:             *      as an IOException or independently as itself.
0924:             * @exception IOException  If an I/O error occurs while either sending the
0925:             *      command or receiving the server reply.
0926:             ***/
0927:            public int retr(String pathname) throws IOException {
0928:                return sendCommand(FTPCommand.RETR, pathname);
0929:            }
0930:
0931:            /***
0932:             * A convenience method to send the FTP STOR command to the server,
0933:             * receive the reply, and return the reply code.  Remember, it is up
0934:             * to you to manage the data connection.  If you don't need this low
0935:             * level of access, use {@link org.apache.commons.net.ftp.FTPClient}
0936:             * , which will handle all low level details for you.
0937:             * <p>
0938:             * @param pathname  The pathname to use for the file when stored at
0939:             *                  the remote end of the transfer.
0940:             * @return The reply code received from the server.
0941:             * @exception FTPConnectionClosedException
0942:             *      If the FTP server prematurely closes the connection as a result
0943:             *      of the client being idle or some other reason causing the server
0944:             *      to send FTP reply code 421.  This exception may be caught either
0945:             *      as an IOException or independently as itself.
0946:             * @exception IOException  If an I/O error occurs while either sending the
0947:             *      command or receiving the server reply.
0948:             ***/
0949:            public int stor(String pathname) throws IOException {
0950:                return sendCommand(FTPCommand.STOR, pathname);
0951:            }
0952:
0953:            /***
0954:             * A convenience method to send the FTP STOU command to the server,
0955:             * receive the reply, and return the reply code.  Remember, it is up
0956:             * to you to manage the data connection.  If you don't need this low
0957:             * level of access, use {@link org.apache.commons.net.ftp.FTPClient}
0958:             * , which will handle all low level details for you.
0959:             * <p>
0960:             * @return The reply code received from the server.
0961:             * @exception FTPConnectionClosedException
0962:             *      If the FTP server prematurely closes the connection as a result
0963:             *      of the client being idle or some other reason causing the server
0964:             *      to send FTP reply code 421.  This exception may be caught either
0965:             *      as an IOException or independently as itself.
0966:             * @exception IOException  If an I/O error occurs while either sending the
0967:             *      command or receiving the server reply.
0968:             ***/
0969:            public int stou() throws IOException {
0970:                return sendCommand(FTPCommand.STOU);
0971:            }
0972:
0973:            /***
0974:             * A convenience method to send the FTP STOU command to the server,
0975:             * receive the reply, and return the reply code.  Remember, it is up
0976:             * to you to manage the data connection.  If you don't need this low
0977:             * level of access, use {@link org.apache.commons.net.ftp.FTPClient}
0978:             * , which will handle all low level details for you.
0979:             * @param pathname  The base pathname to use for the file when stored at
0980:             *                  the remote end of the transfer.  Some FTP servers
0981:             *                  require this.
0982:             * @return The reply code received from the server.
0983:             * @exception FTPConnectionClosedException
0984:             *      If the FTP server prematurely closes the connection as a result
0985:             *      of the client being idle or some other reason causing the server
0986:             *      to send FTP reply code 421.  This exception may be caught either
0987:             *      as an IOException or independently as itself.
0988:             * @exception IOException  If an I/O error occurs while either sending the
0989:             *      command or receiving the server reply.
0990:             */
0991:            public int stou(String pathname) throws IOException {
0992:                return sendCommand(FTPCommand.STOU, pathname);
0993:            }
0994:
0995:            /***
0996:             * A convenience method to send the FTP APPE command to the server,
0997:             * receive the reply, and return the reply code.  Remember, it is up
0998:             * to you to manage the data connection.  If you don't need this low
0999:             * level of access, use {@link org.apache.commons.net.ftp.FTPClient}
1000:             * , which will handle all low level details for you.
1001:             * <p>
1002:             * @param pathname  The pathname to use for the file when stored at
1003:             *                  the remote end of the transfer.
1004:             * @return The reply code received from the server.
1005:             * @exception FTPConnectionClosedException
1006:             *      If the FTP server prematurely closes the connection as a result
1007:             *      of the client being idle or some other reason causing the server
1008:             *      to send FTP reply code 421.  This exception may be caught either
1009:             *      as an IOException or independently as itself.
1010:             * @exception IOException  If an I/O error occurs while either sending the
1011:             *      command or receiving the server reply.
1012:             ***/
1013:            public int appe(String pathname) throws IOException {
1014:                return sendCommand(FTPCommand.APPE, pathname);
1015:            }
1016:
1017:            /***
1018:             * A convenience method to send the FTP ALLO command to the server,
1019:             * receive the reply, and return the reply code.
1020:             * <p>
1021:             * @param bytes The number of bytes to allocate.
1022:             * @return The reply code received from the server.
1023:             * @exception FTPConnectionClosedException
1024:             *      If the FTP server prematurely closes the connection as a result
1025:             *      of the client being idle or some other reason causing the server
1026:             *      to send FTP reply code 421.  This exception may be caught either
1027:             *      as an IOException or independently as itself.
1028:             * @exception IOException  If an I/O error occurs while either sending the
1029:             *      command or receiving the server reply.
1030:             ***/
1031:            public int allo(int bytes) throws IOException {
1032:                return sendCommand(FTPCommand.ALLO, Integer.toString(bytes));
1033:            }
1034:
1035:            /***
1036:             * A convenience method to send the FTP ALLO command to the server,
1037:             * receive the reply, and return the reply code.
1038:             * <p>
1039:             * @param bytes The number of bytes to allocate.
1040:             * @param recordSize  The size of a record.
1041:             * @return The reply code received from the server.
1042:             * @exception FTPConnectionClosedException
1043:             *      If the FTP server prematurely closes the connection as a result
1044:             *      of the client being idle or some other reason causing the server
1045:             *      to send FTP reply code 421.  This exception may be caught either
1046:             *      as an IOException or independently as itself.
1047:             * @exception IOException  If an I/O error occurs while either sending the
1048:             *      command or receiving the server reply.
1049:             ***/
1050:            public int allo(int bytes, int recordSize) throws IOException {
1051:                return sendCommand(FTPCommand.ALLO, Integer.toString(bytes)
1052:                        + " R " + Integer.toString(recordSize));
1053:            }
1054:
1055:            /***
1056:             * A convenience method to send the FTP REST command to the server,
1057:             * receive the reply, and return the reply code.
1058:             * <p>
1059:             * @param marker The marker at which to restart a transfer.
1060:             * @return The reply code received from the server.
1061:             * @exception FTPConnectionClosedException
1062:             *      If the FTP server prematurely closes the connection as a result
1063:             *      of the client being idle or some other reason causing the server
1064:             *      to send FTP reply code 421.  This exception may be caught either
1065:             *      as an IOException or independently as itself.
1066:             * @exception IOException  If an I/O error occurs while either sending the
1067:             *      command or receiving the server reply.
1068:             ***/
1069:            public int rest(String marker) throws IOException {
1070:                return sendCommand(FTPCommand.REST, marker);
1071:            }
1072:
1073:            /***
1074:             * A convenience method to send the FTP RNFR command to the server,
1075:             * receive the reply, and return the reply code.
1076:             * <p>
1077:             * @param pathname The pathname to rename from.
1078:             * @return The reply code received from the server.
1079:             * @exception FTPConnectionClosedException
1080:             *      If the FTP server prematurely closes the connection as a result
1081:             *      of the client being idle or some other reason causing the server
1082:             *      to send FTP reply code 421.  This exception may be caught either
1083:             *      as an IOException or independently as itself.
1084:             * @exception IOException  If an I/O error occurs while either sending the
1085:             *      command or receiving the server reply.
1086:             ***/
1087:            public int rnfr(String pathname) throws IOException {
1088:                return sendCommand(FTPCommand.RNFR, pathname);
1089:            }
1090:
1091:            /***
1092:             * A convenience method to send the FTP RNTO command to the server,
1093:             * receive the reply, and return the reply code.
1094:             * <p>
1095:             * @param pathname The pathname to rename to
1096:             * @return The reply code received from the server.
1097:             * @exception FTPConnectionClosedException
1098:             *      If the FTP server prematurely closes the connection as a result
1099:             *      of the client being idle or some other reason causing the server
1100:             *      to send FTP reply code 421.  This exception may be caught either
1101:             *      as an IOException or independently as itself.
1102:             * @exception IOException  If an I/O error occurs while either sending the
1103:             *      command or receiving the server reply.
1104:             ***/
1105:            public int rnto(String pathname) throws IOException {
1106:                return sendCommand(FTPCommand.RNTO, pathname);
1107:            }
1108:
1109:            /***
1110:             * A convenience method to send the FTP DELE command to the server,
1111:             * receive the reply, and return the reply code.
1112:             * <p>
1113:             * @param pathname The pathname to delete.
1114:             * @return The reply code received from the server.
1115:             * @exception FTPConnectionClosedException
1116:             *      If the FTP server prematurely closes the connection as a result
1117:             *      of the client being idle or some other reason causing the server
1118:             *      to send FTP reply code 421.  This exception may be caught either
1119:             *      as an IOException or independently as itself.
1120:             * @exception IOException  If an I/O error occurs while either sending the
1121:             *      command or receiving the server reply.
1122:             ***/
1123:            public int dele(String pathname) throws IOException {
1124:                return sendCommand(FTPCommand.DELE, pathname);
1125:            }
1126:
1127:            /***
1128:             * A convenience method to send the FTP RMD command to the server,
1129:             * receive the reply, and return the reply code.
1130:             * <p>
1131:             * @param pathname The pathname of the directory to remove.
1132:             * @return The reply code received from the server.
1133:             * @exception FTPConnectionClosedException
1134:             *      If the FTP server prematurely closes the connection as a result
1135:             *      of the client being idle or some other reason causing the server
1136:             *      to send FTP reply code 421.  This exception may be caught either
1137:             *      as an IOException or independently as itself.
1138:             * @exception IOException  If an I/O error occurs while either sending the
1139:             *      command or receiving the server reply.
1140:             ***/
1141:            public int rmd(String pathname) throws IOException {
1142:                return sendCommand(FTPCommand.RMD, pathname);
1143:            }
1144:
1145:            /***
1146:             * A convenience method to send the FTP MKD command to the server,
1147:             * receive the reply, and return the reply code.
1148:             * <p>
1149:             * @param pathname The pathname of the new directory to create.
1150:             * @return The reply code received from the server.
1151:             * @exception FTPConnectionClosedException
1152:             *      If the FTP server prematurely closes the connection as a result
1153:             *      of the client being idle or some other reason causing the server
1154:             *      to send FTP reply code 421.  This exception may be caught either
1155:             *      as an IOException or independently as itself.
1156:             * @exception IOException  If an I/O error occurs while either sending the
1157:             *      command or receiving the server reply.
1158:             ***/
1159:            public int mkd(String pathname) throws IOException {
1160:                return sendCommand(FTPCommand.MKD, pathname);
1161:            }
1162:
1163:            /***
1164:             * A convenience method to send the FTP PWD command to the server,
1165:             * receive the reply, and return the reply code.
1166:             * <p>
1167:             * @return The reply code received from the server.
1168:             * @exception FTPConnectionClosedException
1169:             *      If the FTP server prematurely closes the connection as a result
1170:             *      of the client being idle or some other reason causing the server
1171:             *      to send FTP reply code 421.  This exception may be caught either
1172:             *      as an IOException or independently as itself.
1173:             * @exception IOException  If an I/O error occurs while either sending the
1174:             *      command or receiving the server reply.
1175:             ***/
1176:            public int pwd() throws IOException {
1177:                return sendCommand(FTPCommand.PWD);
1178:            }
1179:
1180:            /***
1181:             * A convenience method to send the FTP LIST command to the server,
1182:             * receive the reply, and return the reply code.  Remember, it is up
1183:             * to you to manage the data connection.  If you don't need this low
1184:             * level of access, use {@link org.apache.commons.net.ftp.FTPClient}
1185:             * , which will handle all low level details for you.
1186:             * <p>
1187:             * @return The reply code received from the server.
1188:             * @exception FTPConnectionClosedException
1189:             *      If the FTP server prematurely closes the connection as a result
1190:             *      of the client being idle or some other reason causing the server
1191:             *      to send FTP reply code 421.  This exception may be caught either
1192:             *      as an IOException or independently as itself.
1193:             * @exception IOException  If an I/O error occurs while either sending the
1194:             *      command or receiving the server reply.
1195:             ***/
1196:            public int list() throws IOException {
1197:                return sendCommand(FTPCommand.LIST);
1198:            }
1199:
1200:            /***
1201:             * A convenience method to send the FTP LIST command to the server,
1202:             * receive the reply, and return the reply code.  Remember, it is up
1203:             * to you to manage the data connection.  If you don't need this low
1204:             * level of access, use {@link org.apache.commons.net.ftp.FTPClient}
1205:             * , which will handle all low level details for you.
1206:             * <p>
1207:             * @param pathname  The pathname to list.
1208:             * @return The reply code received from the server.
1209:             * @exception FTPConnectionClosedException
1210:             *      If the FTP server prematurely closes the connection as a result
1211:             *      of the client being idle or some other reason causing the server
1212:             *      to send FTP reply code 421.  This exception may be caught either
1213:             *      as an IOException or independently as itself.
1214:             * @exception IOException  If an I/O error occurs while either sending the
1215:             *      command or receiving the server reply.
1216:             ***/
1217:            public int list(String pathname) throws IOException {
1218:                return sendCommand(FTPCommand.LIST, pathname);
1219:            }
1220:
1221:            /***
1222:             * A convenience method to send the FTP NLST command to the server,
1223:             * receive the reply, and return the reply code.  Remember, it is up
1224:             * to you to manage the data connection.  If you don't need this low
1225:             * level of access, use {@link org.apache.commons.net.ftp.FTPClient}
1226:             * , which will handle all low level details for you.
1227:             * <p>
1228:             * @return The reply code received from the server.
1229:             * @exception FTPConnectionClosedException
1230:             *      If the FTP server prematurely closes the connection as a result
1231:             *      of the client being idle or some other reason causing the server
1232:             *      to send FTP reply code 421.  This exception may be caught either
1233:             *      as an IOException or independently as itself.
1234:             * @exception IOException  If an I/O error occurs while either sending the
1235:             *      command or receiving the server reply.
1236:             ***/
1237:            public int nlst() throws IOException {
1238:                return sendCommand(FTPCommand.NLST);
1239:            }
1240:
1241:            /***
1242:             * A convenience method to send the FTP NLST command to the server,
1243:             * receive the reply, and return the reply code.  Remember, it is up
1244:             * to you to manage the data connection.  If you don't need this low
1245:             * level of access, use {@link org.apache.commons.net.ftp.FTPClient}
1246:             * , which will handle all low level details for you.
1247:             * <p>
1248:             * @param pathname  The pathname to list.
1249:             * @return The reply code received from the server.
1250:             * @exception FTPConnectionClosedException
1251:             *      If the FTP server prematurely closes the connection as a result
1252:             *      of the client being idle or some other reason causing the server
1253:             *      to send FTP reply code 421.  This exception may be caught either
1254:             *      as an IOException or independently as itself.
1255:             * @exception IOException  If an I/O error occurs while either sending the
1256:             *      command or receiving the server reply.
1257:             ***/
1258:            public int nlst(String pathname) throws IOException {
1259:                return sendCommand(FTPCommand.NLST, pathname);
1260:            }
1261:
1262:            /***
1263:             * A convenience method to send the FTP SITE command to the server,
1264:             * receive the reply, and return the reply code.
1265:             * <p>
1266:             * @param parameters  The site parameters to send.
1267:             * @return The reply code received from the server.
1268:             * @exception FTPConnectionClosedException
1269:             *      If the FTP server prematurely closes the connection as a result
1270:             *      of the client being idle or some other reason causing the server
1271:             *      to send FTP reply code 421.  This exception may be caught either
1272:             *      as an IOException or independently as itself.
1273:             * @exception IOException  If an I/O error occurs while either sending the
1274:             *      command or receiving the server reply.
1275:             ***/
1276:            public int site(String parameters) throws IOException {
1277:                return sendCommand(FTPCommand.SITE, parameters);
1278:            }
1279:
1280:            /***
1281:             * A convenience method to send the FTP SYST command to the server,
1282:             * receive the reply, and return the reply code.
1283:             * <p>
1284:             * @return The reply code received from the server.
1285:             * @exception FTPConnectionClosedException
1286:             *      If the FTP server prematurely closes the connection as a result
1287:             *      of the client being idle or some other reason causing the server
1288:             *      to send FTP reply code 421.  This exception may be caught either
1289:             *      as an IOException or independently as itself.
1290:             * @exception IOException  If an I/O error occurs while either sending the
1291:             *      command or receiving the server reply.
1292:             ***/
1293:            public int syst() throws IOException {
1294:                return sendCommand(FTPCommand.SYST);
1295:            }
1296:
1297:            /***
1298:             * A convenience method to send the FTP STAT command to the server,
1299:             * receive the reply, and return the reply code.
1300:             * <p>
1301:             * @return The reply code received from the server.
1302:             * @exception FTPConnectionClosedException
1303:             *      If the FTP server prematurely closes the connection as a result
1304:             *      of the client being idle or some other reason causing the server
1305:             *      to send FTP reply code 421.  This exception may be caught either
1306:             *      as an IOException or independently as itself.
1307:             * @exception IOException  If an I/O error occurs while either sending the
1308:             *      command or receiving the server reply.
1309:             ***/
1310:            public int stat() throws IOException {
1311:                return sendCommand(FTPCommand.STAT);
1312:            }
1313:
1314:            /***
1315:             * A convenience method to send the FTP STAT command to the server,
1316:             * receive the reply, and return the reply code.
1317:             * <p>
1318:             * @param pathname  A pathname to list.
1319:             * @return The reply code received from the server.
1320:             * @exception FTPConnectionClosedException
1321:             *      If the FTP server prematurely closes the connection as a result
1322:             *      of the client being idle or some other reason causing the server
1323:             *      to send FTP reply code 421.  This exception may be caught either
1324:             *      as an IOException or independently as itself.
1325:             * @exception IOException  If an I/O error occurs while either sending the
1326:             *      command or receiving the server reply.
1327:             ***/
1328:            public int stat(String pathname) throws IOException {
1329:                return sendCommand(FTPCommand.STAT, pathname);
1330:            }
1331:
1332:            /***
1333:             * A convenience method to send the FTP HELP command to the server,
1334:             * receive the reply, and return the reply code.
1335:             * <p>
1336:             * @return The reply code received from the server.
1337:             * @exception FTPConnectionClosedException
1338:             *      If the FTP server prematurely closes the connection as a result
1339:             *      of the client being idle or some other reason causing the server
1340:             *      to send FTP reply code 421.  This exception may be caught either
1341:             *      as an IOException or independently as itself.
1342:             * @exception IOException  If an I/O error occurs while either sending the
1343:             *      command or receiving the server reply.
1344:             ***/
1345:            public int help() throws IOException {
1346:                return sendCommand(FTPCommand.HELP);
1347:            }
1348:
1349:            /***
1350:             * A convenience method to send the FTP HELP command to the server,
1351:             * receive the reply, and return the reply code.
1352:             * <p>
1353:             * @param command  The command name on which to request help.
1354:             * @return The reply code received from the server.
1355:             * @exception FTPConnectionClosedException
1356:             *      If the FTP server prematurely closes the connection as a result
1357:             *      of the client being idle or some other reason causing the server
1358:             *      to send FTP reply code 421.  This exception may be caught either
1359:             *      as an IOException or independently as itself.
1360:             * @exception IOException  If an I/O error occurs while either sending the
1361:             *      command or receiving the server reply.
1362:             ***/
1363:            public int help(String command) throws IOException {
1364:                return sendCommand(FTPCommand.HELP, command);
1365:            }
1366:
1367:            /***
1368:             * A convenience method to send the FTP NOOP command to the server,
1369:             * receive the reply, and return the reply code.
1370:             * <p>
1371:             * @return The reply code received from the server.
1372:             * @exception FTPConnectionClosedException
1373:             *      If the FTP server prematurely closes the connection as a result
1374:             *      of the client being idle or some other reason causing the server
1375:             *      to send FTP reply code 421.  This exception may be caught either
1376:             *      as an IOException or independently as itself.
1377:             * @exception IOException  If an I/O error occurs while either sending the
1378:             *      command or receiving the server reply.
1379:             ***/
1380:            public int noop() throws IOException {
1381:                return sendCommand(FTPCommand.NOOP);
1382:            }
1383:
1384:        }
1385:
1386:        /* Emacs configuration
1387:         * Local variables:        **
1388:         * mode:             java  **
1389:         * c-basic-offset:   4     **
1390:         * indent-tabs-mode: nil   **
1391:         * End:                    **
1392:         */
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.