001    /*
002     * Licensed to the Apache Software Foundation (ASF) under one or more
003     * contributor license agreements.  See the NOTICE file distributed with
004     * this work for additional information regarding copyright ownership.
005     * The ASF licenses this file to You under the Apache License, Version 2.0
006     * (the "License"); you may not use this file except in compliance with
007     * the License.  You may obtain a copy of the License at
008     *
009     *      http://www.apache.org/licenses/LICENSE-2.0
010     *
011     * Unless required by applicable law or agreed to in writing, software
012     * distributed under the License is distributed on an "AS IS" BASIS,
013     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014     * See the License for the specific language governing permissions and
015     * limitations under the License.
016     */
017    
018    package org.apache.commons.net.ftp;
019    import java.io.BufferedReader;
020    import java.io.BufferedWriter;
021    import java.io.IOException;
022    import java.io.InputStreamReader;
023    import java.io.OutputStreamWriter;
024    import java.net.Inet4Address;
025    import java.net.Inet6Address;
026    import java.net.InetAddress;
027    import java.net.Socket;
028    import java.net.SocketException;
029    import java.util.ArrayList;
030    
031    import org.apache.commons.net.MalformedServerReplyException;
032    import org.apache.commons.net.ProtocolCommandListener;
033    import org.apache.commons.net.ProtocolCommandSupport;
034    import org.apache.commons.net.SocketClient;
035    
036    /***
037     * FTP provides the basic the functionality necessary to implement your
038     * own FTP client.  It extends org.apache.commons.net.SocketClient since
039     * extending TelnetClient was causing unwanted behavior (like connections
040     * that did not time out properly).
041     * <p>
042     * To derive the full benefits of the FTP class requires some knowledge
043     * of the FTP protocol defined in RFC 959.  However, there is no reason
044     * why you should have to use the FTP class.  The
045     * {@link org.apache.commons.net.ftp.FTPClient} class,
046     * derived from FTP,
047     * implements all the functionality required of an FTP client.  The
048     * FTP class is made public to provide access to various FTP constants
049     * and to make it easier for adventurous programmers (or those with
050     * special needs) to interact with the FTP protocol and implement their
051     * own clients.  A set of methods with names corresponding to the FTP
052     * command names are provided to facilitate this interaction.
053     * <p>
054     * You should keep in mind that the FTP server may choose to prematurely
055     * close a connection if the client has been idle for longer than a
056     * given time period (usually 900 seconds).  The FTP class will detect a
057     * premature FTP server connection closing when it receives a
058     * {@link org.apache.commons.net.ftp.FTPReply#SERVICE_NOT_AVAILABLE FTPReply.SERVICE_NOT_AVAILABLE }
059     *  response to a command.
060     * When that occurs, the FTP class method encountering that reply will throw
061     * an {@link org.apache.commons.net.ftp.FTPConnectionClosedException}
062     * .  <code>FTPConectionClosedException</code>
063     * is a subclass of <code> IOException </code> and therefore need not be
064     * caught separately, but if you are going to catch it separately, its
065     * catch block must appear before the more general <code> IOException </code>
066     * catch block.  When you encounter an
067     * {@link org.apache.commons.net.ftp.FTPConnectionClosedException}
068     * , you must disconnect the connection with
069     * {@link #disconnect  disconnect() } to properly clean up the
070     * system resources used by FTP.  Before disconnecting, you may check the
071     * last reply code and text with
072     * {@link #getReplyCode  getReplyCode },
073     * {@link #getReplyString  getReplyString },
074     * and {@link #getReplyStrings  getReplyStrings}.
075     * You may avoid server disconnections while the client is idle by
076     * periodicaly sending NOOP commands to the server.
077     * <p>
078     * Rather than list it separately for each method, we mention here that
079     * every method communicating with the server and throwing an IOException
080     * can also throw a
081     * {@link org.apache.commons.net.MalformedServerReplyException}
082     * , which is a subclass
083     * of IOException.  A MalformedServerReplyException will be thrown when
084     * the reply received from the server deviates enough from the protocol
085     * specification that it cannot be interpreted in a useful manner despite
086     * attempts to be as lenient as possible.
087     * <p>
088     * <p>
089     * @author Daniel F. Savarese
090     * @author Rory Winston
091     * @author Joseph Hindsley
092     * @see FTPClient
093     * @see FTPConnectionClosedException
094     * @see org.apache.commons.net.MalformedServerReplyException
095     * @version $Id: FTP.java 1032954 2010-11-09 12:15:10Z sebb $
096     ***/
097    
098    public class FTP extends SocketClient
099    {
100        /*** The default FTP data port (20). ***/
101        public static final int DEFAULT_DATA_PORT = 20;
102        /*** The default FTP control port (21). ***/
103        public static final int DEFAULT_PORT = 21;
104    
105        /***
106         * A constant used to indicate the file(s) being transfered should
107         * be treated as ASCII.  This is the default file type.  All constants
108         * ending in <code>FILE_TYPE</code> are used to indicate file types.
109         ***/
110        public static final int ASCII_FILE_TYPE = 0;
111    
112        /***
113         * A constant used to indicate the file(s) being transfered should
114         * be treated as EBCDIC.  Note however that there are several different
115         * EBCDIC formats.  All constants ending in <code>FILE_TYPE</code>
116         * are used to indicate file types.
117         ***/
118        public static final int EBCDIC_FILE_TYPE = 1;
119    
120    
121        /***
122         * A constant used to indicate the file(s) being transfered should
123         * be treated as a binary image, i.e., no translations should be
124         * performed.  All constants ending in <code>FILE_TYPE</code> are used to
125         * indicate file types.
126         ***/
127        public static final int BINARY_FILE_TYPE = 2;
128    
129        /***
130         * A constant used to indicate the file(s) being transfered should
131         * be treated as a local type.  All constants ending in
132         * <code>FILE_TYPE</code> are used to indicate file types.
133         ***/
134        public static final int LOCAL_FILE_TYPE = 3;
135    
136        /***
137         * A constant used for text files to indicate a non-print text format.
138         * This is the default format.
139         * All constants ending in <code>TEXT_FORMAT</code> are used to indicate
140         * text formatting for text transfers (both ASCII and EBCDIC).
141         ***/
142        public static final int NON_PRINT_TEXT_FORMAT = 4;
143    
144        /***
145         * A constant used to indicate a text file contains format vertical format
146         * control characters.
147         * All constants ending in <code>TEXT_FORMAT</code> are used to indicate
148         * text formatting for text transfers (both ASCII and EBCDIC).
149         ***/
150        public static final int TELNET_TEXT_FORMAT = 5;
151    
152        /***
153         * A constant used to indicate a text file contains ASA vertical format
154         * control characters.
155         * All constants ending in <code>TEXT_FORMAT</code> are used to indicate
156         * text formatting for text transfers (both ASCII and EBCDIC).
157         ***/
158        public static final int CARRIAGE_CONTROL_TEXT_FORMAT = 6;
159    
160        /***
161         * A constant used to indicate a file is to be treated as a continuous
162         * sequence of bytes.  This is the default structure.  All constants ending
163         * in <code>_STRUCTURE</code> are used to indicate file structure for
164         * file transfers.
165         ***/
166        public static final int FILE_STRUCTURE = 7;
167    
168        /***
169         * A constant used to indicate a file is to be treated as a sequence
170         * of records.  All constants ending in <code>_STRUCTURE</code>
171         * are used to indicate file structure for file transfers.
172         ***/
173        public static final int RECORD_STRUCTURE = 8;
174    
175        /***
176         * A constant used to indicate a file is to be treated as a set of
177         * independent indexed pages.  All constants ending in
178         * <code>_STRUCTURE</code> are used to indicate file structure for file
179         * transfers.
180         ***/
181        public static final int PAGE_STRUCTURE = 9;
182    
183        /***
184         * A constant used to indicate a file is to be transfered as a stream
185         * of bytes.  This is the default transfer mode.  All constants ending
186         * in <code>TRANSFER_MODE</code> are used to indicate file transfer
187         * modes.
188         ***/
189        public static final int STREAM_TRANSFER_MODE = 10;
190    
191        /***
192         * A constant used to indicate a file is to be transfered as a series
193         * of blocks.  All constants ending in <code>TRANSFER_MODE</code> are used
194         * to indicate file transfer modes.
195         ***/
196        public static final int BLOCK_TRANSFER_MODE = 11;
197    
198        /***
199         * A constant used to indicate a file is to be transfered as FTP
200         * compressed data.  All constants ending in <code>TRANSFER_MODE</code>
201         * are used to indicate file transfer modes.
202         ***/
203        public static final int COMPRESSED_TRANSFER_MODE = 12;
204    
205        // We have to ensure that the protocol communication is in ASCII
206        // but we use ISO-8859-1 just in case 8-bit characters cross
207        // the wire.
208        /**
209         * The default character encoding used for communicating over an
210         * FTP control connection.  The default encoding is an
211         * ASCII-compatible encoding.  Some FTP servers expect other
212         * encodings.  You can change the encoding used by an FTP instance
213         * with {@link #setControlEncoding setControlEncoding}.
214         */
215        public static final String DEFAULT_CONTROL_ENCODING = "ISO-8859-1";
216        private static final String __modes = "AEILNTCFRPSBC";
217    
218        private final StringBuilder __commandBuffer = new StringBuilder();
219    
220        protected int _replyCode;
221        protected ArrayList<String> _replyLines;
222        protected boolean _newReplyString;
223        protected String _replyString;
224        protected String _controlEncoding;
225    
226        /**
227         * This is used to signal whether a block of multiline responses beginning
228         * with xxx must be terminated by the same numeric code xxx
229         * See section 4.2 of RFC 959 for details.
230         */
231        protected boolean strictMultilineParsing = false;
232    
233        /**
234         * Wraps SocketClient._input_ to facilitate the writing of text
235         * to the FTP control connection.  Do not access the control
236         * connection via SocketClient._input_.  This member starts
237         * with a null value, is initialized in {@link #_connectAction_},
238         * and set to null in {@link #disconnect}.
239         */
240        protected BufferedReader _controlInput_;
241    
242        /**
243         * Wraps SocketClient._output_ to facilitate the reading of text
244         * from the FTP control connection.  Do not access the control
245         * connection via SocketClient._output_.  This member starts
246         * with a null value, is initialized in {@link #_connectAction_},
247         * and set to null in {@link #disconnect}.
248         */
249        protected BufferedWriter _controlOutput_;
250    
251        /***
252         * A ProtocolCommandSupport object used to manage the registering of
253         * ProtocolCommandListeners and te firing of ProtocolCommandEvents.
254         ***/
255        protected ProtocolCommandSupport _commandSupport_;
256    
257        /***
258         * The default FTP constructor.  Sets the default port to
259         * <code>DEFAULT_PORT</code> and initializes internal data structures
260         * for saving FTP reply information.
261         ***/
262        public FTP()
263        {
264            super();
265            setDefaultPort(DEFAULT_PORT);
266            _replyLines = new ArrayList<String>();
267            _newReplyString = false;
268            _replyString = null;
269            _commandSupport_ = new ProtocolCommandSupport(this);
270            _controlEncoding = DEFAULT_CONTROL_ENCODING;
271        }
272    
273        // The RFC-compliant multiline termination check
274        private boolean __strictCheck(String line, String code) {
275            return (!(line.startsWith(code) && line.charAt(3) == ' '));
276        }
277    
278        // The strict check is too strong a condition because of non-conforming ftp
279        // servers like ftp.funet.fi which sent 226 as the last line of a
280        // 426 multi-line reply in response to ls /.  We relax the condition to
281        // test that the line starts with a digit rather than starting with
282        // the code.
283        private boolean __lenientCheck(String line) {
284            return (!(line.length() >= 4 && line.charAt(3) != '-' &&
285                    Character.isDigit(line.charAt(0))));
286        }
287    
288        private void __getReply() throws IOException
289        {
290            int length;
291    
292            _newReplyString = true;
293            _replyLines.clear();
294    
295            String line = _controlInput_.readLine();
296    
297            if (line == null)
298                throw new FTPConnectionClosedException(
299                    "Connection closed without indication.");
300    
301            // In case we run into an anomaly we don't want fatal index exceptions
302            // to be thrown.
303            length = line.length();
304            if (length < 3)
305                throw new MalformedServerReplyException(
306                    "Truncated server reply: " + line);
307    
308            String code = null;
309            try
310            {
311                code = line.substring(0, 3);
312                _replyCode = Integer.parseInt(code);
313            }
314            catch (NumberFormatException e)
315            {
316                throw new MalformedServerReplyException(
317                    "Could not parse response code.\nServer Reply: " + line);
318            }
319    
320            _replyLines.add(line);
321    
322            // Get extra lines if message continues.
323            if (length > 3 && line.charAt(3) == '-')
324            {
325                do
326                {
327                    line = _controlInput_.readLine();
328    
329                    if (line == null)
330                        throw new FTPConnectionClosedException(
331                            "Connection closed without indication.");
332    
333                    _replyLines.add(line);
334    
335                    // The length() check handles problems that could arise from readLine()
336                    // returning too soon after encountering a naked CR or some other
337                    // anomaly.
338                }
339                while ( isStrictMultilineParsing() ? __strictCheck(line, code) : __lenientCheck(line));
340            }
341    
342            if (_commandSupport_.getListenerCount() > 0) {
343                _commandSupport_.fireReplyReceived(_replyCode, getReplyString());
344            }
345    
346            if (_replyCode == FTPReply.SERVICE_NOT_AVAILABLE) {
347                throw new FTPConnectionClosedException("FTP response 421 received.  Server closed connection.");
348            }
349        }
350    
351        /**
352         * Initiates control connections and gets initial reply.
353         * Initializes {@link #_controlInput_} and {@link #_controlOutput_}.
354         */
355        @Override
356        protected void _connectAction_() throws IOException
357        {
358            super._connectAction_();
359            _controlInput_ =
360                new BufferedReader(new InputStreamReader(_socket_.getInputStream(),
361                                                         getControlEncoding()));
362            _controlOutput_ =
363                new BufferedWriter(new OutputStreamWriter(_socket_.getOutputStream(),
364                                                          getControlEncoding()));
365            __getReply();
366            // If we received code 120, we have to fetch completion reply.
367            if (FTPReply.isPositivePreliminary(_replyCode))
368                __getReply();
369        }
370    
371    
372        /**
373         * Sets the character encoding used by the FTP control connection.
374         * Some FTP servers require that commands be issued in a non-ASCII
375         * encoding like UTF-8 so that filenames with multi-byte character
376         * representations (e.g, Big 8) can be specified.
377         *
378         * @param encoding The new character encoding for the control connection.
379         */
380        public void setControlEncoding(String encoding) {
381            _controlEncoding = encoding;
382        }
383    
384    
385        /**
386         * @return The character encoding used to communicate over the
387         * control connection.
388         */
389        public String getControlEncoding() {
390            return _controlEncoding;
391        }
392    
393    
394        /***
395         * Adds a ProtocolCommandListener.  Delegates this task to
396         * {@link #_commandSupport_  _commandSupport_ }.
397         * <p>
398         * @param listener  The ProtocolCommandListener to add.
399         ***/
400        public void addProtocolCommandListener(ProtocolCommandListener listener)
401        {
402            _commandSupport_.addProtocolCommandListener(listener);
403        }
404    
405        /***
406         * Removes a ProtocolCommandListener.  Delegates this task to
407         * {@link #_commandSupport_  _commandSupport_ }.
408         * <p>
409         * @param listener  The ProtocolCommandListener to remove.
410         ***/
411        public void removeProtocolCommandListener(ProtocolCommandListener listener)
412        {
413            _commandSupport_.removeProtocolCommandListener(listener);
414        }
415    
416    
417        /***
418         * Closes the control connection to the FTP server and sets to null
419         * some internal data so that the memory may be reclaimed by the
420         * garbage collector.  The reply text and code information from the
421         * last command is voided so that the memory it used may be reclaimed.
422         * Also sets {@link #_controlInput_} and {@link #_controlOutput_} to null.
423         * <p>
424         * @exception IOException If an error occurs while disconnecting.
425         ***/
426        @Override
427        public void disconnect() throws IOException
428        {
429            super.disconnect();
430            _controlInput_ = null;
431            _controlOutput_ = null;
432            _newReplyString = false;
433            _replyString = null;
434        }
435    
436    
437        /***
438         * Sends an FTP command to the server, waits for a reply and returns the
439         * numerical response code.  After invocation, for more detailed
440         * information, the actual reply text can be accessed by calling
441         * {@link #getReplyString  getReplyString } or
442         * {@link #getReplyStrings  getReplyStrings }.
443         * <p>
444         * @param command  The text representation of the  FTP command to send.
445         * @param args The arguments to the FTP command.  If this parameter is
446         *             set to null, then the command is sent with no argument.
447         * @return The integer value of the FTP reply code returned by the server
448         *         in response to the command.
449         * @exception FTPConnectionClosedException
450         *      If the FTP server prematurely closes the connection as a result
451         *      of the client being idle or some other reason causing the server
452         *      to send FTP reply code 421.  This exception may be caught either
453         *      as an IOException or independently as itself.
454         * @exception IOException  If an I/O error occurs while either sending the
455         *      command or receiving the server reply.
456         ***/
457        public int sendCommand(String command, String args) throws IOException
458        {
459            String message;
460    
461            __commandBuffer.setLength(0);
462            __commandBuffer.append(command);
463    
464            if (args != null)
465            {
466                __commandBuffer.append(' ');
467                __commandBuffer.append(args);
468            }
469            __commandBuffer.append(SocketClient.NETASCII_EOL);
470    
471            if (_controlOutput_ == null){
472                throw new IOException("Connection is not open");
473            }
474    
475            try{
476                _controlOutput_.write(message = __commandBuffer.toString());
477                _controlOutput_.flush();
478            }
479            catch (SocketException e)
480            {
481                if (!isConnected() || !socketIsConnected(_socket_))
482                {
483                    throw new FTPConnectionClosedException("Connection unexpectedly closed.");
484                }
485                else
486                {
487                    throw e;
488                }
489            }
490    
491    
492            if (_commandSupport_.getListenerCount() > 0)
493                _commandSupport_.fireCommandSent(command, message);
494    
495            __getReply();
496            return _replyCode;
497        }
498    
499        /**
500         * Checks if the socket is connected
501         *
502         * @param socket
503         * @return true if connected
504         */
505        private boolean socketIsConnected(Socket socket)
506        {
507            if (socket == null)
508            {
509                return false;
510            }
511            return socket.isConnected();
512        }
513    
514        /***
515         * Sends an FTP command to the server, waits for a reply and returns the
516         * numerical response code.  After invocation, for more detailed
517         * information, the actual reply text can be accessed by calling
518         * {@link #getReplyString  getReplyString } or
519         * {@link #getReplyStrings  getReplyStrings }.
520         * <p>
521         * @param command  The FTPCommand constant corresponding to the FTP command
522         *                 to send.
523         * @param args The arguments to the FTP command.  If this parameter is
524         *             set to null, then the command is sent with no argument.
525         * @return The integer value of the FTP reply code returned by the server
526         *         in response to the command.
527         * @exception FTPConnectionClosedException
528         *      If the FTP server prematurely closes the connection as a result
529         *      of the client being idle or some other reason causing the server
530         *      to send FTP reply code 421.  This exception may be caught either
531         *      as an IOException or independently as itself.
532         * @exception IOException  If an I/O error occurs while either sending the
533         *      command or receiving the server reply.
534         ***/
535        public int sendCommand(int command, String args) throws IOException
536        {
537            return sendCommand(FTPCommand.getCommand(command), args);
538        }
539    
540    
541        /***
542         * Sends an FTP command with no arguments to the server, waits for a
543         * reply and returns the numerical response code.  After invocation, for
544         * more detailed information, the actual reply text can be accessed by
545         * calling {@link #getReplyString  getReplyString } or
546         * {@link #getReplyStrings  getReplyStrings }.
547         * <p>
548         * @param command  The text representation of the  FTP command to send.
549         * @return The integer value of the FTP reply code returned by the server
550         *         in response to the command.
551         * @exception FTPConnectionClosedException
552         *      If the FTP server prematurely closes the connection as a result
553         *      of the client being idle or some other reason causing the server
554         *      to send FTP reply code 421.  This exception may be caught either
555         *      as an IOException or independently as itself.
556         * @exception IOException  If an I/O error occurs while either sending the
557         *      command or receiving the server reply.
558         ***/
559        public int sendCommand(String command) throws IOException
560        {
561            return sendCommand(command, null);
562        }
563    
564    
565        /***
566         * Sends an FTP command with no arguments to the server, waits for a
567         * reply and returns the numerical response code.  After invocation, for
568         * more detailed information, the actual reply text can be accessed by
569         * calling {@link #getReplyString  getReplyString } or
570         * {@link #getReplyStrings  getReplyStrings }.
571         * <p>
572         * @param command  The FTPCommand constant corresponding to the FTP command
573         *                 to send.
574         * @return The integer value of the FTP reply code returned by the server
575         *         in response to the command.
576         * @exception FTPConnectionClosedException
577         *      If the FTP server prematurely closes the connection as a result
578         *      of the client being idle or some other reason causing the server
579         *      to send FTP reply code 421.  This exception may be caught either
580         *      as an IOException or independently as itself.
581         * @exception IOException  If an I/O error occurs while either sending the
582         *      command or receiving the server reply.
583         ***/
584        public int sendCommand(int command) throws IOException
585        {
586            return sendCommand(command, null);
587        }
588    
589    
590        /***
591         * Returns the integer value of the reply code of the last FTP reply.
592         * You will usually only use this method after you connect to the
593         * FTP server to check that the connection was successful since
594         * <code> connect </code> is of type void.
595         * <p>
596         * @return The integer value of the reply code of the last FTP reply.
597         ***/
598        public int getReplyCode()
599        {
600            return _replyCode;
601        }
602    
603        /***
604         * Fetches a reply from the FTP server and returns the integer reply
605         * code.  After calling this method, the actual reply text can be accessed
606         * from either  calling {@link #getReplyString  getReplyString } or
607         * {@link #getReplyStrings  getReplyStrings }.  Only use this
608         * method if you are implementing your own FTP client or if you need to
609         * fetch a secondary response from the FTP server.
610         * <p>
611         * @return The integer value of the reply code of the fetched FTP reply.
612         * @exception FTPConnectionClosedException
613         *      If the FTP server prematurely closes the connection as a result
614         *      of the client being idle or some other reason causing the server
615         *      to send FTP reply code 421.  This exception may be caught either
616         *      as an IOException or independently as itself.
617         * @exception IOException  If an I/O error occurs while receiving the
618         *                         server reply.
619         ***/
620        public int getReply() throws IOException
621        {
622            __getReply();
623            return _replyCode;
624        }
625    
626    
627        /***
628         * Returns the lines of text from the last FTP server response as an array
629         * of strings, one entry per line.  The end of line markers of each are
630         * stripped from each line.
631         * <p>
632         * @return The lines of text from the last FTP response as an array.
633         ***/
634        public String[] getReplyStrings()
635        {
636            return _replyLines.toArray(new String[_replyLines.size()]);
637        }
638    
639        /***
640         * Returns the entire text of the last FTP server response exactly
641         * as it was received, including all end of line markers in NETASCII
642         * format.
643         * <p>
644         * @return The entire text from the last FTP response as a String.
645         ***/
646        public String getReplyString()
647        {
648            StringBuilder buffer;
649    
650            if (!_newReplyString) {
651                return _replyString;
652            }
653    
654            buffer = new StringBuilder(256);
655    
656            for (String line : _replyLines) {
657                    buffer.append(line);
658                    buffer.append(SocketClient.NETASCII_EOL);
659            }
660    
661             _newReplyString = false;
662    
663            return (_replyString = buffer.toString());
664        }
665    
666    
667        /***
668         * A convenience method to send the FTP USER command to the server,
669         * receive the reply, and return the reply code.
670         * <p>
671         * @param username  The username to login under.
672         * @return The reply code received from the server.
673         * @exception FTPConnectionClosedException
674         *      If the FTP server prematurely closes the connection as a result
675         *      of the client being idle or some other reason causing the server
676         *      to send FTP reply code 421.  This exception may be caught either
677         *      as an IOException or independently as itself.
678         * @exception IOException  If an I/O error occurs while either sending the
679         *      command or receiving the server reply.
680         ***/
681        public int user(String username) throws IOException
682        {
683            return sendCommand(FTPCommand.USER, username);
684        }
685    
686        /**
687         * A convenience method to send the FTP PASS command to the server,
688         * receive the reply, and return the reply code.
689         * @param password The plain text password of the username being logged into.
690         * @return The reply code received from the server.
691         * @exception FTPConnectionClosedException
692         *      If the FTP server prematurely closes the connection as a result
693         *      of the client being idle or some other reason causing the server
694         *      to send FTP reply code 421.  This exception may be caught either
695         *      as an IOException or independently as itself.
696         * @exception IOException  If an I/O error occurs while either sending the
697         *      command or receiving the server reply.
698         */
699        public int pass(String password) throws IOException
700        {
701            return sendCommand(FTPCommand.PASS, password);
702        }
703    
704        /***
705         * A convenience method to send the FTP ACCT command to the server,
706         * receive the reply, and return the reply code.
707         * <p>
708         * @param account  The account name to access.
709         * @return The reply code received from the server.
710         * @exception FTPConnectionClosedException
711         *      If the FTP server prematurely closes the connection as a result
712         *      of the client being idle or some other reason causing the server
713         *      to send FTP reply code 421.  This exception may be caught either
714         *      as an IOException or independently as itself.
715         * @exception IOException  If an I/O error occurs while either sending the
716         *      command or receiving the server reply.
717         ***/
718        public int acct(String account) throws IOException
719        {
720            return sendCommand(FTPCommand.ACCT, account);
721        }
722    
723    
724        /***
725         * A convenience method to send the FTP ABOR command to the server,
726         * receive the reply, and return the reply code.
727         * <p>
728         * @return The reply code received from the server.
729         * @exception FTPConnectionClosedException
730         *      If the FTP server prematurely closes the connection as a result
731         *      of the client being idle or some other reason causing the server
732         *      to send FTP reply code 421.  This exception may be caught either
733         *      as an IOException or independently as itself.
734         * @exception IOException  If an I/O error occurs while either sending the
735         *      command or receiving the server reply.
736         ***/
737        public int abor() throws IOException
738        {
739            return sendCommand(FTPCommand.ABOR);
740        }
741    
742        /***
743         * A convenience method to send the FTP CWD command to the server,
744         * receive the reply, and return the reply code.
745         * <p>
746         * @param directory The new working directory.
747         * @return The reply code received from the server.
748         * @exception FTPConnectionClosedException
749         *      If the FTP server prematurely closes the connection as a result
750         *      of the client being idle or some other reason causing the server
751         *      to send FTP reply code 421.  This exception may be caught either
752         *      as an IOException or independently as itself.
753         * @exception IOException  If an I/O error occurs while either sending the
754         *      command or receiving the server reply.
755         ***/
756        public int cwd(String directory) throws IOException
757        {
758            return sendCommand(FTPCommand.CWD, directory);
759        }
760    
761        /***
762         * A convenience method to send the FTP CDUP command to the server,
763         * receive the reply, and return the reply code.
764         * <p>
765         * @return The reply code received from the server.
766         * @exception FTPConnectionClosedException
767         *      If the FTP server prematurely closes the connection as a result
768         *      of the client being idle or some other reason causing the server
769         *      to send FTP reply code 421.  This exception may be caught either
770         *      as an IOException or independently as itself.
771         * @exception IOException  If an I/O error occurs while either sending the
772         *      command or receiving the server reply.
773         ***/
774        public int cdup() throws IOException
775        {
776            return sendCommand(FTPCommand.CDUP);
777        }
778    
779        /***
780         * A convenience method to send the FTP QUIT command to the server,
781         * receive the reply, and return the reply code.
782         * <p>
783         * @return The reply code received from the server.
784         * @exception FTPConnectionClosedException
785         *      If the FTP server prematurely closes the connection as a result
786         *      of the client being idle or some other reason causing the server
787         *      to send FTP reply code 421.  This exception may be caught either
788         *      as an IOException or independently as itself.
789         * @exception IOException  If an I/O error occurs while either sending the
790         *      command or receiving the server reply.
791         ***/
792        public int quit() throws IOException
793        {
794            return sendCommand(FTPCommand.QUIT);
795        }
796    
797        /***
798         * A convenience method to send the FTP REIN command to the server,
799         * receive the reply, and return the reply code.
800         * <p>
801         * @return The reply code received from the server.
802         * @exception FTPConnectionClosedException
803         *      If the FTP server prematurely closes the connection as a result
804         *      of the client being idle or some other reason causing the server
805         *      to send FTP reply code 421.  This exception may be caught either
806         *      as an IOException or independently as itself.
807         * @exception IOException  If an I/O error occurs while either sending the
808         *      command or receiving the server reply.
809         ***/
810        public int rein() throws IOException
811        {
812            return sendCommand(FTPCommand.REIN);
813        }
814    
815        /***
816         * A convenience method to send the FTP SMNT command to the server,
817         * receive the reply, and return the reply code.
818         * <p>
819         * @param dir  The directory name.
820         * @return The reply code received from the server.
821         * @exception FTPConnectionClosedException
822         *      If the FTP server prematurely closes the connection as a result
823         *      of the client being idle or some other reason causing the server
824         *      to send FTP reply code 421.  This exception may be caught either
825         *      as an IOException or independently as itself.
826         * @exception IOException  If an I/O error occurs while either sending the
827         *      command or receiving the server reply.
828         ***/
829        public int smnt(String dir) throws IOException
830        {
831            return sendCommand(FTPCommand.SMNT, dir);
832        }
833    
834        /***
835         * A convenience method to send the FTP PORT command to the server,
836         * receive the reply, and return the reply code.
837         * <p>
838         * @param host  The host owning the port.
839         * @param port  The new port.
840         * @return The reply code received from the server.
841         * @exception FTPConnectionClosedException
842         *      If the FTP server prematurely closes the connection as a result
843         *      of the client being idle or some other reason causing the server
844         *      to send FTP reply code 421.  This exception may be caught either
845         *      as an IOException or independently as itself.
846         * @exception IOException  If an I/O error occurs while either sending the
847         *      command or receiving the server reply.
848         ***/
849        public int port(InetAddress host, int port) throws IOException
850        {
851            int num;
852            StringBuilder info = new StringBuilder(24);
853    
854            info.append(host.getHostAddress().replace('.', ','));
855            num = port >>> 8;
856            info.append(',');
857            info.append(num);
858            info.append(',');
859            num = port & 0xff;
860            info.append(num);
861    
862            return sendCommand(FTPCommand.PORT, info.toString());
863        }
864    
865        /***
866         * A convenience method to send the FTP EPRT command to the server,
867         * receive the reply, and return the reply code.
868         *
869         * Examples:
870         * <code>
871         * <ul>
872         * <li>EPRT |1|132.235.1.2|6275|</li>
873         * <li>EPRT |2|1080::8:800:200C:417A|5282|</li>
874         * </ul>
875         * </code>
876         * <p>
877         * @see "http://www.faqs.org/rfcs/rfc2428.html"
878         *
879         * @param host  The host owning the port.
880         * @param port  The new port.
881         * @return The reply code received from the server.
882         * @exception FTPConnectionClosedException
883         *      If the FTP server prematurely closes the connection as a result
884         *      of the client being idle or some other reason causing the server
885         *      to send FTP reply code 421.  This exception may be caught either
886         *      as an IOException or independently as itself.
887         * @exception IOException  If an I/O error occurs while either sending the
888         *      command or receiving the server reply.
889         * @since 2.2
890         ***/
891        public int eprt(InetAddress host, int port) throws IOException
892        {
893            int num;
894            StringBuilder info = new StringBuilder();
895            String h;
896    
897            // If IPv6, trim the zone index
898            h = host.getHostAddress();
899            num = h.indexOf("%");
900            if (num > 0)
901                h = h.substring(0, num);
902    
903            info.append("|");
904    
905            if (host instanceof Inet4Address)
906                info.append("1");
907            else if (host instanceof Inet6Address)
908                info.append("2");
909            info.append("|");
910            info.append(h);
911            info.append("|");
912            info.append(port);
913            info.append("|");
914    
915            return sendCommand(FTPCommand.EPRT, info.toString());
916        }
917    
918        /***
919         * A convenience method to send the FTP PASV command to the server,
920         * receive the reply, and return the reply code.  Remember, it's up
921         * to you to interpret the reply string containing the host/port
922         * information.
923         * <p>
924         * @return The reply code received from the server.
925         * @exception FTPConnectionClosedException
926         *      If the FTP server prematurely closes the connection as a result
927         *      of the client being idle or some other reason causing the server
928         *      to send FTP reply code 421.  This exception may be caught either
929         *      as an IOException or independently as itself.
930         * @exception IOException  If an I/O error occurs while either sending the
931         *      command or receiving the server reply.
932         ***/
933        public int pasv() throws IOException
934        {
935            return sendCommand(FTPCommand.PASV);
936        }
937    
938         /***
939         * A convenience method to send the FTP EPSV command to the server,
940         * receive the reply, and return the reply code.  Remember, it's up
941         * to you to interpret the reply string containing the host/port
942         * information.
943         * <p>
944         * @return The reply code received from the server.
945         * @exception FTPConnectionClosedException
946         *      If the FTP server prematurely closes the connection as a result
947         *      of the client being idle or some other reason causing the server
948         *      to send FTP reply code 421.  This exception may be caught either
949         *      as an IOException or independently as itself.
950         * @exception IOException  If an I/O error occurs while either sending the
951         *      command or receiving the server reply.
952         * @since 2.2
953         ***/
954        public int epsv() throws IOException
955        {
956            return sendCommand(FTPCommand.EPSV);
957        }
958    
959        /**
960         * A convenience method to send the FTP TYPE command for text files
961         * to the server, receive the reply, and return the reply code.
962         * @param fileType  The type of the file (one of the <code>FILE_TYPE</code>
963         *              constants).
964         * @param formatOrByteSize  The format of the file (one of the
965         *              <code>_FORMAT</code> constants.  In the case of
966         *              <code>LOCAL_FILE_TYPE</code>, the byte size.
967         * @return The reply code received from the server.
968         * @exception FTPConnectionClosedException
969         *      If the FTP server prematurely closes the connection as a result
970         *      of the client being idle or some other reason causing the server
971         *      to send FTP reply code 421.  This exception may be caught either
972         *      as an IOException or independently as itself.
973         * @exception IOException  If an I/O error occurs while either sending the
974         *      command or receiving the server reply.
975         */
976        public int type(int fileType, int formatOrByteSize) throws IOException
977        {
978            StringBuilder arg = new StringBuilder();
979    
980            arg.append(__modes.charAt(fileType));
981            arg.append(' ');
982            if (fileType == LOCAL_FILE_TYPE)
983                arg.append(formatOrByteSize);
984            else
985                arg.append(__modes.charAt(formatOrByteSize));
986    
987            return sendCommand(FTPCommand.TYPE, arg.toString());
988        }
989    
990    
991        /**
992         * A convenience method to send the FTP TYPE command to the server,
993         * receive the reply, and return the reply code.
994         * <p>
995         * @param fileType  The type of the file (one of the <code>FILE_TYPE</code>
996         *              constants).
997         * @return The reply code received from the server.
998         * @exception FTPConnectionClosedException
999         *      If the FTP server prematurely closes the connection as a result
1000         *      of the client being idle or some other reason causing the server
1001         *      to send FTP reply code 421.  This exception may be caught either
1002         *      as an IOException or independently as itself.
1003         * @exception IOException  If an I/O error occurs while either sending the
1004         *      command or receiving the server reply.
1005         */
1006        public int type(int fileType) throws IOException
1007        {
1008            return sendCommand(FTPCommand.TYPE,
1009                               __modes.substring(fileType, fileType + 1));
1010        }
1011    
1012        /***
1013         * A convenience method to send the FTP STRU command to the server,
1014         * receive the reply, and return the reply code.
1015         * <p>
1016         * @param structure  The structure of the file (one of the
1017         *         <code>_STRUCTURE</code> constants).
1018         * @return The reply code received from the server.
1019         * @exception FTPConnectionClosedException
1020         *      If the FTP server prematurely closes the connection as a result
1021         *      of the client being idle or some other reason causing the server
1022         *      to send FTP reply code 421.  This exception may be caught either
1023         *      as an IOException or independently as itself.
1024         * @exception IOException  If an I/O error occurs while either sending the
1025         *      command or receiving the server reply.
1026         ***/
1027        public int stru(int structure) throws IOException
1028        {
1029            return sendCommand(FTPCommand.STRU,
1030                               __modes.substring(structure, structure + 1));
1031        }
1032    
1033        /***
1034         * A convenience method to send the FTP MODE command to the server,
1035         * receive the reply, and return the reply code.
1036         * <p>
1037         * @param mode  The transfer mode to use (one of the
1038         *         <code>TRANSFER_MODE</code> constants).
1039         * @return The reply code received from the server.
1040         * @exception FTPConnectionClosedException
1041         *      If the FTP server prematurely closes the connection as a result
1042         *      of the client being idle or some other reason causing the server
1043         *      to send FTP reply code 421.  This exception may be caught either
1044         *      as an IOException or independently as itself.
1045         * @exception IOException  If an I/O error occurs while either sending the
1046         *      command or receiving the server reply.
1047         ***/
1048        public int mode(int mode) throws IOException
1049        {
1050            return sendCommand(FTPCommand.MODE,
1051                               __modes.substring(mode, mode + 1));
1052        }
1053    
1054        /***
1055         * A convenience method to send the FTP RETR command to the server,
1056         * receive the reply, and return the reply code.  Remember, it is up
1057         * to you to manage the data connection.  If you don't need this low
1058         * level of access, use {@link org.apache.commons.net.ftp.FTPClient}
1059         * , which will handle all low level details for you.
1060         * <p>
1061         * @param pathname  The pathname of the file to retrieve.
1062         * @return The reply code received from the server.
1063         * @exception FTPConnectionClosedException
1064         *      If the FTP server prematurely closes the connection as a result
1065         *      of the client being idle or some other reason causing the server
1066         *      to send FTP reply code 421.  This exception may be caught either
1067         *      as an IOException or independently as itself.
1068         * @exception IOException  If an I/O error occurs while either sending the
1069         *      command or receiving the server reply.
1070         ***/
1071        public int retr(String pathname) throws IOException
1072        {
1073            return sendCommand(FTPCommand.RETR, pathname);
1074        }
1075    
1076        /***
1077         * A convenience method to send the FTP STOR command to the server,
1078         * receive the reply, and return the reply code.  Remember, it is up
1079         * to you to manage the data connection.  If you don't need this low
1080         * level of access, use {@link org.apache.commons.net.ftp.FTPClient}
1081         * , which will handle all low level details for you.
1082         * <p>
1083         * @param pathname  The pathname to use for the file when stored at
1084         *                  the remote end of the transfer.
1085         * @return The reply code received from the server.
1086         * @exception FTPConnectionClosedException
1087         *      If the FTP server prematurely closes the connection as a result
1088         *      of the client being idle or some other reason causing the server
1089         *      to send FTP reply code 421.  This exception may be caught either
1090         *      as an IOException or independently as itself.
1091         * @exception IOException  If an I/O error occurs while either sending the
1092         *      command or receiving the server reply.
1093         ***/
1094        public int stor(String pathname) throws IOException
1095        {
1096            return sendCommand(FTPCommand.STOR, pathname);
1097        }
1098    
1099        /***
1100         * A convenience method to send the FTP STOU command to the server,
1101         * receive the reply, and return the reply code.  Remember, it is up
1102         * to you to manage the data connection.  If you don't need this low
1103         * level of access, use {@link org.apache.commons.net.ftp.FTPClient}
1104         * , which will handle all low level details for you.
1105         * <p>
1106         * @return The reply code received from the server.
1107         * @exception FTPConnectionClosedException
1108         *      If the FTP server prematurely closes the connection as a result
1109         *      of the client being idle or some other reason causing the server
1110         *      to send FTP reply code 421.  This exception may be caught either
1111         *      as an IOException or independently as itself.
1112         * @exception IOException  If an I/O error occurs while either sending the
1113         *      command or receiving the server reply.
1114         ***/
1115        public int stou() throws IOException
1116        {
1117            return sendCommand(FTPCommand.STOU);
1118        }
1119    
1120        /***
1121         * A convenience method to send the FTP STOU command to the server,
1122         * receive the reply, and return the reply code.  Remember, it is up
1123         * to you to manage the data connection.  If you don't need this low
1124         * level of access, use {@link org.apache.commons.net.ftp.FTPClient}
1125         * , which will handle all low level details for you.
1126         * @param pathname  The base pathname to use for the file when stored at
1127         *                  the remote end of the transfer.  Some FTP servers
1128         *                  require this.
1129         * @return The reply code received from the server.
1130         * @exception FTPConnectionClosedException
1131         *      If the FTP server prematurely closes the connection as a result
1132         *      of the client being idle or some other reason causing the server
1133         *      to send FTP reply code 421.  This exception may be caught either
1134         *      as an IOException or independently as itself.
1135         * @exception IOException  If an I/O error occurs while either sending the
1136         *      command or receiving the server reply.
1137         */
1138        public int stou(String pathname) throws IOException
1139        {
1140            return sendCommand(FTPCommand.STOU, pathname);
1141        }
1142    
1143        /***
1144         * A convenience method to send the FTP APPE command to the server,
1145         * receive the reply, and return the reply code.  Remember, it is up
1146         * to you to manage the data connection.  If you don't need this low
1147         * level of access, use {@link org.apache.commons.net.ftp.FTPClient}
1148         * , which will handle all low level details for you.
1149         * <p>
1150         * @param pathname  The pathname to use for the file when stored at
1151         *                  the remote end of the transfer.
1152         * @return The reply code received from the server.
1153         * @exception FTPConnectionClosedException
1154         *      If the FTP server prematurely closes the connection as a result
1155         *      of the client being idle or some other reason causing the server
1156         *      to send FTP reply code 421.  This exception may be caught either
1157         *      as an IOException or independently as itself.
1158         * @exception IOException  If an I/O error occurs while either sending the
1159         *      command or receiving the server reply.
1160         ***/
1161        public int appe(String pathname) throws IOException
1162        {
1163            return sendCommand(FTPCommand.APPE, pathname);
1164        }
1165    
1166        /***
1167         * A convenience method to send the FTP ALLO command to the server,
1168         * receive the reply, and return the reply code.
1169         * <p>
1170         * @param bytes The number of bytes to allocate.
1171         * @return The reply code received from the server.
1172         * @exception FTPConnectionClosedException
1173         *      If the FTP server prematurely closes the connection as a result
1174         *      of the client being idle or some other reason causing the server
1175         *      to send FTP reply code 421.  This exception may be caught either
1176         *      as an IOException or independently as itself.
1177         * @exception IOException  If an I/O error occurs while either sending the
1178         *      command or receiving the server reply.
1179         ***/
1180        public int allo(int bytes) throws IOException
1181        {
1182            return sendCommand(FTPCommand.ALLO, Integer.toString(bytes));
1183        }
1184    
1185        /**
1186         * A convenience method to send the FTP FEAT command to the server, receive the reply,
1187         * and return the reply code.
1188         * @return The reply code received by the server
1189         * @throws IOException  If an I/O error occurs while either sending the
1190         *      command or receiving the server reply.
1191         * @since 2.2
1192         */
1193        public int feat() throws IOException
1194        {
1195            return sendCommand(FTPCommand.FEAT);
1196        }
1197    
1198        /***
1199         * A convenience method to send the FTP ALLO command to the server,
1200         * receive the reply, and return the reply code.
1201         * <p>
1202         * @param bytes The number of bytes to allocate.
1203         * @param recordSize  The size of a record.
1204         * @return The reply code received from the server.
1205         * @exception FTPConnectionClosedException
1206         *      If the FTP server prematurely closes the connection as a result
1207         *      of the client being idle or some other reason causing the server
1208         *      to send FTP reply code 421.  This exception may be caught either
1209         *      as an IOException or independently as itself.
1210         * @exception IOException  If an I/O error occurs while either sending the
1211         *      command or receiving the server reply.
1212         ***/
1213        public int allo(int bytes, int recordSize) throws IOException
1214        {
1215            return sendCommand(FTPCommand.ALLO, Integer.toString(bytes) + " R " +
1216                               Integer.toString(recordSize));
1217        }
1218    
1219        /***
1220         * A convenience method to send the FTP REST command to the server,
1221         * receive the reply, and return the reply code.
1222         * <p>
1223         * @param marker The marker at which to restart a transfer.
1224         * @return The reply code received from the server.
1225         * @exception FTPConnectionClosedException
1226         *      If the FTP server prematurely closes the connection as a result
1227         *      of the client being idle or some other reason causing the server
1228         *      to send FTP reply code 421.  This exception may be caught either
1229         *      as an IOException or independently as itself.
1230         * @exception IOException  If an I/O error occurs while either sending the
1231         *      command or receiving the server reply.
1232         ***/
1233        public int rest(String marker) throws IOException
1234        {
1235            return sendCommand(FTPCommand.REST, marker);
1236        }
1237    
1238    
1239        /**
1240         * @since 2.0
1241         **/
1242        public int mdtm(String file) throws IOException
1243        {
1244            return sendCommand(FTPCommand.MDTM, file);
1245        }
1246    
1247    
1248        /**
1249         * A convenience method to send the FTP MFMT command to the server,
1250         * receive the reply, and return the reply code.
1251         * <p>
1252         * @param pathname The pathname for which mtime is to be changed
1253         * @param timeval Timestamp in <code>YYYYMMDDhhmmss</code> format
1254         * @return The reply code received from the server.
1255         * @exception FTPConnectionClosedException
1256         *      If the FTP server prematurely closes the connection as a result
1257         *      of the client being idle or some other reason causing the server
1258         *      to send FTP reply code 421.  This exception may be caught either
1259         *      as an IOException or independently as itself.
1260         * @exception IOException  If an I/O error occurs while either sending the
1261         *      command or receiving the server reply.
1262         * @since 2.2
1263         * @see <a href="http://tools.ietf.org/html/draft-somers-ftp-mfxx-04">http://tools.ietf.org/html/draft-somers-ftp-mfxx-04</a>
1264         **/
1265        public int mfmt(String pathname, String timeval) throws IOException
1266        {
1267            return sendCommand(FTPCommand.MFMT, timeval + " " + pathname);
1268        }
1269    
1270    
1271        /***
1272         * A convenience method to send the FTP RNFR command to the server,
1273         * receive the reply, and return the reply code.
1274         * <p>
1275         * @param pathname The pathname to rename from.
1276         * @return The reply code received from the server.
1277         * @exception FTPConnectionClosedException
1278         *      If the FTP server prematurely closes the connection as a result
1279         *      of the client being idle or some other reason causing the server
1280         *      to send FTP reply code 421.  This exception may be caught either
1281         *      as an IOException or independently as itself.
1282         * @exception IOException  If an I/O error occurs while either sending the
1283         *      command or receiving the server reply.
1284         ***/
1285        public int rnfr(String pathname) throws IOException
1286        {
1287            return sendCommand(FTPCommand.RNFR, pathname);
1288        }
1289    
1290        /***
1291         * A convenience method to send the FTP RNTO command to the server,
1292         * receive the reply, and return the reply code.
1293         * <p>
1294         * @param pathname The pathname to rename to
1295         * @return The reply code received from the server.
1296         * @exception FTPConnectionClosedException
1297         *      If the FTP server prematurely closes the connection as a result
1298         *      of the client being idle or some other reason causing the server
1299         *      to send FTP reply code 421.  This exception may be caught either
1300         *      as an IOException or independently as itself.
1301         * @exception IOException  If an I/O error occurs while either sending the
1302         *      command or receiving the server reply.
1303         ***/
1304        public int rnto(String pathname) throws IOException
1305        {
1306            return sendCommand(FTPCommand.RNTO, pathname);
1307        }
1308    
1309        /***
1310         * A convenience method to send the FTP DELE command to the server,
1311         * receive the reply, and return the reply code.
1312         * <p>
1313         * @param pathname The pathname to delete.
1314         * @return The reply code received from the server.
1315         * @exception FTPConnectionClosedException
1316         *      If the FTP server prematurely closes the connection as a result
1317         *      of the client being idle or some other reason causing the server
1318         *      to send FTP reply code 421.  This exception may be caught either
1319         *      as an IOException or independently as itself.
1320         * @exception IOException  If an I/O error occurs while either sending the
1321         *      command or receiving the server reply.
1322         ***/
1323        public int dele(String pathname) throws IOException
1324        {
1325            return sendCommand(FTPCommand.DELE, pathname);
1326        }
1327    
1328        /***
1329         * A convenience method to send the FTP RMD command to the server,
1330         * receive the reply, and return the reply code.
1331         * <p>
1332         * @param pathname The pathname of the directory to remove.
1333         * @return The reply code received from the server.
1334         * @exception FTPConnectionClosedException
1335         *      If the FTP server prematurely closes the connection as a result
1336         *      of the client being idle or some other reason causing the server
1337         *      to send FTP reply code 421.  This exception may be caught either
1338         *      as an IOException or independently as itself.
1339         * @exception IOException  If an I/O error occurs while either sending the
1340         *      command or receiving the server reply.
1341         ***/
1342        public int rmd(String pathname) throws IOException
1343        {
1344            return sendCommand(FTPCommand.RMD, pathname);
1345        }
1346    
1347        /***
1348         * A convenience method to send the FTP MKD command to the server,
1349         * receive the reply, and return the reply code.
1350         * <p>
1351         * @param pathname The pathname of the new directory to create.
1352         * @return The reply code received from the server.
1353         * @exception FTPConnectionClosedException
1354         *      If the FTP server prematurely closes the connection as a result
1355         *      of the client being idle or some other reason causing the server
1356         *      to send FTP reply code 421.  This exception may be caught either
1357         *      as an IOException or independently as itself.
1358         * @exception IOException  If an I/O error occurs while either sending the
1359         *      command or receiving the server reply.
1360         ***/
1361        public int mkd(String pathname) throws IOException
1362        {
1363            return sendCommand(FTPCommand.MKD, pathname);
1364        }
1365    
1366        /***
1367         * A convenience method to send the FTP PWD command to the server,
1368         * receive the reply, and return the reply code.
1369         * <p>
1370         * @return The reply code received from the server.
1371         * @exception FTPConnectionClosedException
1372         *      If the FTP server prematurely closes the connection as a result
1373         *      of the client being idle or some other reason causing the server
1374         *      to send FTP reply code 421.  This exception may be caught either
1375         *      as an IOException or independently as itself.
1376         * @exception IOException  If an I/O error occurs while either sending the
1377         *      command or receiving the server reply.
1378         ***/
1379        public int pwd() throws IOException
1380        {
1381            return sendCommand(FTPCommand.PWD);
1382        }
1383    
1384        /***
1385         * A convenience method to send the FTP LIST command to the server,
1386         * receive the reply, and return the reply code.  Remember, it is up
1387         * to you to manage the data connection.  If you don't need this low
1388         * level of access, use {@link org.apache.commons.net.ftp.FTPClient}
1389         * , which will handle all low level details for you.
1390         * <p>
1391         * @return The reply code received from the server.
1392         * @exception FTPConnectionClosedException
1393         *      If the FTP server prematurely closes the connection as a result
1394         *      of the client being idle or some other reason causing the server
1395         *      to send FTP reply code 421.  This exception may be caught either
1396         *      as an IOException or independently as itself.
1397         * @exception IOException  If an I/O error occurs while either sending the
1398         *      command or receiving the server reply.
1399         ***/
1400        public int list() throws IOException
1401        {
1402            return sendCommand(FTPCommand.LIST);
1403        }
1404    
1405        /***
1406         * A convenience method to send the FTP LIST command to the server,
1407         * receive the reply, and return the reply code.  Remember, it is up
1408         * to you to manage the data connection.  If you don't need this low
1409         * level of access, use {@link org.apache.commons.net.ftp.FTPClient}
1410         * , which will handle all low level details for you.
1411         * <p>
1412         * @param pathname  The pathname to list.
1413         * @return The reply code received from the server.
1414         * @exception FTPConnectionClosedException
1415         *      If the FTP server prematurely closes the connection as a result
1416         *      of the client being idle or some other reason causing the server
1417         *      to send FTP reply code 421.  This exception may be caught either
1418         *      as an IOException or independently as itself.
1419         * @exception IOException  If an I/O error occurs while either sending the
1420         *      command or receiving the server reply.
1421         ***/
1422        public int list(String pathname) throws IOException
1423        {
1424            return sendCommand(FTPCommand.LIST, pathname);
1425        }
1426    
1427        /***
1428         * A convenience method to send the FTP NLST command to the server,
1429         * receive the reply, and return the reply code.  Remember, it is up
1430         * to you to manage the data connection.  If you don't need this low
1431         * level of access, use {@link org.apache.commons.net.ftp.FTPClient}
1432         * , which will handle all low level details for you.
1433         * <p>
1434         * @return The reply code received from the server.
1435         * @exception FTPConnectionClosedException
1436         *      If the FTP server prematurely closes the connection as a result
1437         *      of the client being idle or some other reason causing the server
1438         *      to send FTP reply code 421.  This exception may be caught either
1439         *      as an IOException or independently as itself.
1440         * @exception IOException  If an I/O error occurs while either sending the
1441         *      command or receiving the server reply.
1442         ***/
1443        public int nlst() throws IOException
1444        {
1445            return sendCommand(FTPCommand.NLST);
1446        }
1447    
1448        /***
1449         * A convenience method to send the FTP NLST command to the server,
1450         * receive the reply, and return the reply code.  Remember, it is up
1451         * to you to manage the data connection.  If you don't need this low
1452         * level of access, use {@link org.apache.commons.net.ftp.FTPClient}
1453         * , which will handle all low level details for you.
1454         * <p>
1455         * @param pathname  The pathname to list.
1456         * @return The reply code received from the server.
1457         * @exception FTPConnectionClosedException
1458         *      If the FTP server prematurely closes the connection as a result
1459         *      of the client being idle or some other reason causing the server
1460         *      to send FTP reply code 421.  This exception may be caught either
1461         *      as an IOException or independently as itself.
1462         * @exception IOException  If an I/O error occurs while either sending the
1463         *      command or receiving the server reply.
1464         ***/
1465        public int nlst(String pathname) throws IOException
1466        {
1467            return sendCommand(FTPCommand.NLST, pathname);
1468        }
1469    
1470        /***
1471         * A convenience method to send the FTP SITE command to the server,
1472         * receive the reply, and return the reply code.
1473         * <p>
1474         * @param parameters  The site parameters to send.
1475         * @return The reply code received from the server.
1476         * @exception FTPConnectionClosedException
1477         *      If the FTP server prematurely closes the connection as a result
1478         *      of the client being idle or some other reason causing the server
1479         *      to send FTP reply code 421.  This exception may be caught either
1480         *      as an IOException or independently as itself.
1481         * @exception IOException  If an I/O error occurs while either sending the
1482         *      command or receiving the server reply.
1483         ***/
1484        public int site(String parameters) throws IOException
1485        {
1486            return sendCommand(FTPCommand.SITE, parameters);
1487        }
1488    
1489        /***
1490         * A convenience method to send the FTP SYST command to the server,
1491         * receive the reply, and return the reply code.
1492         * <p>
1493         * @return The reply code received from the server.
1494         * @exception FTPConnectionClosedException
1495         *      If the FTP server prematurely closes the connection as a result
1496         *      of the client being idle or some other reason causing the server
1497         *      to send FTP reply code 421.  This exception may be caught either
1498         *      as an IOException or independently as itself.
1499         * @exception IOException  If an I/O error occurs while either sending the
1500         *      command or receiving the server reply.
1501         ***/
1502        public int syst() throws IOException
1503        {
1504            return sendCommand(FTPCommand.SYST);
1505        }
1506    
1507        /***
1508         * A convenience method to send the FTP STAT command to the server,
1509         * receive the reply, and return the reply code.
1510         * <p>
1511         * @return The reply code received from the server.
1512         * @exception FTPConnectionClosedException
1513         *      If the FTP server prematurely closes the connection as a result
1514         *      of the client being idle or some other reason causing the server
1515         *      to send FTP reply code 421.  This exception may be caught either
1516         *      as an IOException or independently as itself.
1517         * @exception IOException  If an I/O error occurs while either sending the
1518         *      command or receiving the server reply.
1519         ***/
1520        public int stat() throws IOException
1521        {
1522            return sendCommand(FTPCommand.STAT);
1523        }
1524    
1525        /***
1526         * A convenience method to send the FTP STAT command to the server,
1527         * receive the reply, and return the reply code.
1528         * <p>
1529         * @param pathname  A pathname to list.
1530         * @return The reply code received from the server.
1531         * @exception FTPConnectionClosedException
1532         *      If the FTP server prematurely closes the connection as a result
1533         *      of the client being idle or some other reason causing the server
1534         *      to send FTP reply code 421.  This exception may be caught either
1535         *      as an IOException or independently as itself.
1536         * @exception IOException  If an I/O error occurs while either sending the
1537         *      command or receiving the server reply.
1538         ***/
1539        public int stat(String pathname) throws IOException
1540        {
1541            return sendCommand(FTPCommand.STAT, pathname);
1542        }
1543    
1544        /***
1545         * A convenience method to send the FTP HELP command to the server,
1546         * receive the reply, and return the reply code.
1547         * <p>
1548         * @return The reply code received from the server.
1549         * @exception FTPConnectionClosedException
1550         *      If the FTP server prematurely closes the connection as a result
1551         *      of the client being idle or some other reason causing the server
1552         *      to send FTP reply code 421.  This exception may be caught either
1553         *      as an IOException or independently as itself.
1554         * @exception IOException  If an I/O error occurs while either sending the
1555         *      command or receiving the server reply.
1556         ***/
1557        public int help() throws IOException
1558        {
1559            return sendCommand(FTPCommand.HELP);
1560        }
1561    
1562        /***
1563         * A convenience method to send the FTP HELP command to the server,
1564         * receive the reply, and return the reply code.
1565         * <p>
1566         * @param command  The command name on which to request help.
1567         * @return The reply code received from the server.
1568         * @exception FTPConnectionClosedException
1569         *      If the FTP server prematurely closes the connection as a result
1570         *      of the client being idle or some other reason causing the server
1571         *      to send FTP reply code 421.  This exception may be caught either
1572         *      as an IOException or independently as itself.
1573         * @exception IOException  If an I/O error occurs while either sending the
1574         *      command or receiving the server reply.
1575         ***/
1576        public int help(String command) throws IOException
1577        {
1578            return sendCommand(FTPCommand.HELP, command);
1579        }
1580    
1581        /***
1582         * A convenience method to send the FTP NOOP command to the server,
1583         * receive the reply, and return the reply code.
1584         * <p>
1585         * @return The reply code received from the server.
1586         * @exception FTPConnectionClosedException
1587         *      If the FTP server prematurely closes the connection as a result
1588         *      of the client being idle or some other reason causing the server
1589         *      to send FTP reply code 421.  This exception may be caught either
1590         *      as an IOException or independently as itself.
1591         * @exception IOException  If an I/O error occurs while either sending the
1592         *      command or receiving the server reply.
1593         ***/
1594        public int noop() throws IOException
1595        {
1596            return sendCommand(FTPCommand.NOOP);
1597        }
1598    
1599        /**
1600         * Return whether strict multiline parsing is enabled, as per RFC 959, section 4.2.
1601         * @return True if strict, false if lenient
1602         * @since 2.0
1603         */
1604        public boolean isStrictMultilineParsing() {
1605            return strictMultilineParsing;
1606        }
1607    
1608        /**
1609         * Set strict multiline parsing.
1610         * @param strictMultilineParsing
1611         * @since 2.0
1612         */
1613        public void setStrictMultilineParsing(boolean strictMultilineParsing) {
1614            this.strictMultilineParsing = strictMultilineParsing;
1615        }
1616    }
1617    
1618    /* Emacs configuration
1619     * Local variables:        **
1620     * mode:             java  **
1621     * c-basic-offset:   4     **
1622     * indent-tabs-mode: nil   **
1623     * End:                    **
1624     */