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