1. /*
  2. * Copyright 2001-2004 The Apache Software Foundation
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package org.apache.commons.net.ftp;
  17. import java.io.BufferedReader;
  18. import java.io.BufferedWriter;
  19. import java.io.IOException;
  20. import java.io.InputStreamReader;
  21. import java.io.OutputStreamWriter;
  22. import java.net.InetAddress;
  23. import java.util.Enumeration;
  24. import java.util.Vector;
  25. import org.apache.commons.net.MalformedServerReplyException;
  26. import org.apache.commons.net.ProtocolCommandListener;
  27. import org.apache.commons.net.ProtocolCommandSupport;
  28. import org.apache.commons.net.SocketClient;
  29. import org.apache.commons.net.telnet.TelnetClient;
  30. /***
  31. * FTP provides the basic the functionality necessary to implement your
  32. * own FTP client. It extends org.apache.commons.net.TelnetClient
  33. * simply because it saves the writing of extra code to handle the FTP
  34. * control connection which always remains open during an FTP session and
  35. * uses the Telnet protocol. Aggregation would require writing new
  36. * wrapper methods and wouldn't leverage the functionality already
  37. * present in org.apache.commons.net.SocketClient.
  38. * <p>
  39. * To derive the full benefits of the FTP class requires some knowledge
  40. * of the FTP protocol defined in RFC 959. However, there is no reason
  41. * why you should have to use the FTP class. The
  42. * <a href="org.apache.commons.net.ftp.FTPClient.html"> FTPClient </a> class,
  43. * derived from FTP,
  44. * implements all the functionality required of an FTP client. The
  45. * FTP class is made public to provide access to various FTP constants
  46. * and to make it easier for adventurous programmers (or those with
  47. * special needs) to interact with the FTP protocol and implement their
  48. * own clients. A set of methods with names corresponding to the FTP
  49. * command names are provided to facilitate this interaction.
  50. * <p>
  51. * You should keep in mind that the FTP server may choose to prematurely
  52. * close a connection if the client has been idle for longer than a
  53. * given time period (usually 900 seconds). The FTP class will detect a
  54. * premature FTP server connection closing when it receives a
  55. * <a href="org.apache.commons.net.ftp.FTPReply.html#SERVICE_NOT_AVAILABLE">
  56. * FTPReply.SERVICE_NOT_AVAILABLE </a> response to a command.
  57. * When that occurs, the FTP class method encountering that reply will throw
  58. * an <a href="org.apache.commons.net.ftp.FTPConnectionClosedException.html">
  59. * FTPConnectionClosedException </a>. <code>FTPConectionClosedException</code>
  60. * is a subclass of <code> IOException </code> and therefore need not be
  61. * caught separately, but if you are going to catch it separately, its
  62. * catch block must appear before the more general <code> IOException </code>
  63. * catch block. When you encounter an
  64. * <a href="org.apache.commons.net.ftp.FTPConnectionClosedException.html">
  65. * FTPConnectionClosedException </a>, you must disconnect the connection with
  66. * <a href="#disconnect"> disconnect() </a> to properly clean up the
  67. * system resources used by FTP. Before disconnecting, you may check the
  68. * last reply code and text with
  69. * <a href="#getReplyCode"> getReplyCode </a>,
  70. * <a href="#getReplyString"> getReplyString </a>,
  71. * and <a href="#getReplyStrings"> getReplyStrings</a>.
  72. * You may avoid server disconnections while the client is idle by
  73. * periodicaly sending NOOP commands to the server.
  74. * <p>
  75. * Rather than list it separately for each method, we mention here that
  76. * every method communicating with the server and throwing an IOException
  77. * can also throw a
  78. * <a href="org.apache.commons.net.MalformedServerReplyException.html">
  79. * MalformedServerReplyException </a>, which is a subclass
  80. * of IOException. A MalformedServerReplyException will be thrown when
  81. * the reply received from the server deviates enough from the protocol
  82. * specification that it cannot be interpreted in a useful manner despite
  83. * attempts to be as lenient as possible.
  84. * <p>
  85. * <p>
  86. * @author Daniel F. Savarese
  87. * @see FTPClient
  88. * @see FTPConnectionClosedException
  89. * @see org.apache.commons.net.MalformedServerReplyException
  90. ***/
  91. public class FTP extends TelnetClient
  92. {
  93. /*** The default FTP data port (20). ***/
  94. public static final int DEFAULT_DATA_PORT = 20;
  95. /*** The default FTP control port (21). ***/
  96. public static final int DEFAULT_PORT = 21;
  97. /***
  98. * A constant used to indicate the file(s) being transfered should
  99. * be treated as ASCII. This is the default file type. All constants
  100. * ending in <code>FILE_TYPE</code> are used to indicate file types.
  101. ***/
  102. public static final int ASCII_FILE_TYPE = 0;
  103. /***
  104. * A constant used to indicate the file(s) being transfered should
  105. * be treated as EBCDIC. Note however that there are several different
  106. * EBCDIC formats. All constants ending in <code>FILE_TYPE</code>
  107. * are used to indicate file types.
  108. ***/
  109. public static final int EBCDIC_FILE_TYPE = 1;
  110. /***
  111. * A constant used to indicate the file(s) being transfered should
  112. * be treated as a binary image, i.e., no translations should be
  113. * performed. All constants ending in <code>FILE_TYPE</code> are used to
  114. * indicate file types.
  115. ***/
  116. public static final int IMAGE_FILE_TYPE = 2;
  117. /***
  118. * A constant used to indicate the file(s) being transfered should
  119. * be treated as a binary image, i.e., no translations should be
  120. * performed. All constants ending in <code>FILE_TYPE</code> are used to
  121. * indicate file types.
  122. ***/
  123. public static final int BINARY_FILE_TYPE = 2;
  124. /***
  125. * A constant used to indicate the file(s) being transfered should
  126. * be treated as a local type. All constants ending in
  127. * <code>FILE_TYPE</code> are used to indicate file types.
  128. ***/
  129. public static final int LOCAL_FILE_TYPE = 3;
  130. /***
  131. * A constant used for text files to indicate a non-print text format.
  132. * This is the default format.
  133. * All constants ending in <code>TEXT_FORMAT</code> are used to indicate
  134. * text formatting for text transfers (both ASCII and EBCDIC).
  135. ***/
  136. public static final int NON_PRINT_TEXT_FORMAT = 4;
  137. /***
  138. * A constant used to indicate a text file contains format vertical format
  139. * control characters.
  140. * All constants ending in <code>TEXT_FORMAT</code> are used to indicate
  141. * text formatting for text transfers (both ASCII and EBCDIC).
  142. ***/
  143. public static final int TELNET_TEXT_FORMAT = 5;
  144. /***
  145. * A constant used to indicate a text file contains ASA 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 CARRIAGE_CONTROL_TEXT_FORMAT = 6;
  151. /***
  152. * A constant used to indicate a file is to be treated as a continuous
  153. * sequence of bytes. This is the default structure. All constants ending
  154. * in <code>_STRUCTURE</code> are used to indicate file structure for
  155. * file transfers.
  156. ***/
  157. public static final int FILE_STRUCTURE = 7;
  158. /***
  159. * A constant used to indicate a file is to be treated as a sequence
  160. * of records. All constants ending in <code>_STRUCTURE</code>
  161. * are used to indicate file structure for file transfers.
  162. ***/
  163. public static final int RECORD_STRUCTURE = 8;
  164. /***
  165. * A constant used to indicate a file is to be treated as a set of
  166. * independent indexed pages. All constants ending in
  167. * <code>_STRUCTURE</code> are used to indicate file structure for file
  168. * transfers.
  169. ***/
  170. public static final int PAGE_STRUCTURE = 9;
  171. /***
  172. * A constant used to indicate a file is to be transfered as a stream
  173. * of bytes. This is the default transfer mode. All constants ending
  174. * in <code>TRANSFER_MODE</code> are used to indicate file transfer
  175. * modes.
  176. ***/
  177. public static final int STREAM_TRANSFER_MODE = 10;
  178. /***
  179. * A constant used to indicate a file is to be transfered as a series
  180. * of blocks. All constants ending in <code>TRANSFER_MODE</code> are used
  181. * to indicate file transfer modes.
  182. ***/
  183. public static final int BLOCK_TRANSFER_MODE = 11;
  184. /***
  185. * A constant used to indicate a file is to be transfered as FTP
  186. * compressed data. All constants ending in <code>TRANSFER_MODE</code>
  187. * are used to indicate file transfer modes.
  188. ***/
  189. public static final int COMPRESSED_TRANSFER_MODE = 12;
  190. // We have to ensure that the protocol communication is in ASCII
  191. // but we use ISO-8859-1 just in case 8-bit characters cross
  192. // the wire.
  193. private static final String __DEFAULT_ENCODING = "ISO-8859-1";
  194. private static final String __modes = "ABILNTCFRPSBC";
  195. private StringBuffer __commandBuffer;
  196. BufferedReader _controlInput;
  197. BufferedWriter _controlOutput;
  198. int _replyCode;
  199. Vector _replyLines;
  200. boolean _newReplyString;
  201. String _replyString;
  202. /***
  203. * A ProtocolCommandSupport object used to manage the registering of
  204. * ProtocolCommandListeners and te firing of ProtocolCommandEvents.
  205. ***/
  206. protected ProtocolCommandSupport _commandSupport_;
  207. /***
  208. * The default FTP constructor. Sets the default port to
  209. * <code>DEFAULT_PORT</code> and initializes internal data structures
  210. * for saving FTP reply information.
  211. ***/
  212. public FTP()
  213. {
  214. setDefaultPort(DEFAULT_PORT);
  215. __commandBuffer = new StringBuffer();
  216. _replyLines = new Vector();
  217. _newReplyString = false;
  218. _replyString = null;
  219. _commandSupport_ = new ProtocolCommandSupport(this);
  220. }
  221. private void __getReply() throws IOException
  222. {
  223. int length;
  224. _newReplyString = true;
  225. _replyLines.setSize(0);
  226. String line = _controlInput.readLine();
  227. if (line == null)
  228. throw new FTPConnectionClosedException(
  229. "Connection closed without indication.");
  230. // In case we run into an anomaly we don't want fatal index exceptions
  231. // to be thrown.
  232. length = line.length();
  233. if (length < 3)
  234. throw new MalformedServerReplyException(
  235. "Truncated server reply: " + line);
  236. try
  237. {
  238. String code = line.substring(0, 3);
  239. _replyCode = Integer.parseInt(code);
  240. }
  241. catch (NumberFormatException e)
  242. {
  243. throw new MalformedServerReplyException(
  244. "Could not parse response code.\nServer Reply: " + line);
  245. }
  246. _replyLines.addElement(line);
  247. // Get extra lines if message continues.
  248. if (length > 3 && line.charAt(3) == '-')
  249. {
  250. do
  251. {
  252. line = _controlInput.readLine();
  253. if (line == null)
  254. throw new FTPConnectionClosedException(
  255. "Connection closed without indication.");
  256. _replyLines.addElement(line);
  257. // The length() check handles problems that could arise from readLine()
  258. // returning too soon after encountering a naked CR or some other
  259. // anomaly.
  260. }
  261. while (!(line.length() >= 4 && line.charAt(3) != '-' &&
  262. Character.isDigit(line.charAt(0))));
  263. // This is too strong a condition because of non-conforming ftp
  264. // servers like ftp.funet.fi which sent 226 as the last line of a
  265. // 426 multi-line reply in response to ls /. We relax the condition to
  266. // test that the line starts with a digit rather than starting with
  267. // the code.
  268. // line.startsWith(code)));
  269. }
  270. if (_commandSupport_.getListenerCount() > 0)
  271. _commandSupport_.fireReplyReceived(_replyCode, getReplyString());
  272. if (_replyCode == FTPReply.SERVICE_NOT_AVAILABLE)
  273. throw new FTPConnectionClosedException(
  274. "FTP response 421 received. Server closed connection.");
  275. }
  276. // initiates control connections and gets initial reply
  277. protected void _connectAction_() throws IOException
  278. {
  279. super._connectAction_();
  280. _controlInput =
  281. new BufferedReader(new InputStreamReader(getInputStream(),
  282. __DEFAULT_ENCODING));
  283. _controlOutput =
  284. new BufferedWriter(new OutputStreamWriter(getOutputStream(),
  285. __DEFAULT_ENCODING));
  286. __getReply();
  287. // If we received code 120, we have to fetch completion reply.
  288. if (FTPReply.isPositivePreliminary(_replyCode))
  289. __getReply();
  290. }
  291. /***
  292. * Adds a ProtocolCommandListener. Delegates this task to
  293. * <a href="#_commandSupport_"> _commandSupport_ </a>.
  294. * <p>
  295. * @param listener The ProtocolCommandListener to add.
  296. ***/
  297. public void addProtocolCommandListener(ProtocolCommandListener listener)
  298. {
  299. _commandSupport_.addProtocolCommandListener(listener);
  300. }
  301. /***
  302. * Removes a ProtocolCommandListener. Delegates this task to
  303. * <a href="#_commandSupport_"> _commandSupport_ </a>.
  304. * <p>
  305. * @param listener The ProtocolCommandListener to remove.
  306. ***/
  307. public void removeProtocolCommandistener(ProtocolCommandListener listener)
  308. {
  309. _commandSupport_.removeProtocolCommandListener(listener);
  310. }
  311. /***
  312. * Closes the control connection to the FTP server and sets to null
  313. * some internal data so that the memory may be reclaimed by the
  314. * garbage collector. The reply text and code information from the
  315. * last command is voided so that the memory it used may be reclaimed.
  316. * <p>
  317. * @exception IOException If an error occurs while disconnecting.
  318. ***/
  319. public void disconnect() throws IOException
  320. {
  321. super.disconnect();
  322. _controlInput = null;
  323. _controlOutput = null;
  324. _replyLines.setSize(0);
  325. _newReplyString = false;
  326. _replyString = null;
  327. }
  328. /***
  329. * Sends an FTP command to the server, waits for a reply and returns the
  330. * numerical response code. After invocation, for more detailed
  331. * information, the actual reply text can be accessed by calling
  332. * <a href="#getReplyString"> getReplyString </a> or
  333. * <a href="#getReplyStrings"> getReplyStrings </a>.
  334. * <p>
  335. * @param command The text representation of the FTP command to send.
  336. * @param args The arguments to the FTP command. If this parameter is
  337. * set to null, then the command is sent with no argument.
  338. * @return The integer value of the FTP reply code returned by the server
  339. * in response to the command.
  340. * @exception FTPConnectionClosedException
  341. * If the FTP server prematurely closes the connection as a result
  342. * of the client being idle or some other reason causing the server
  343. * to send FTP reply code 421. This exception may be caught either
  344. * as an IOException or independently as itself.
  345. * @exception IOException If an I/O error occurs while either sending the
  346. * command or receiving the server reply.
  347. ***/
  348. public int sendCommand(String command, String args) throws IOException
  349. {
  350. String message;
  351. __commandBuffer.setLength(0);
  352. __commandBuffer.append(command);
  353. if (args != null)
  354. {
  355. __commandBuffer.append(' ');
  356. __commandBuffer.append(args);
  357. }
  358. __commandBuffer.append(SocketClient.NETASCII_EOL);
  359. _controlOutput.write(message = __commandBuffer.toString());
  360. _controlOutput.flush();
  361. if (_commandSupport_.getListenerCount() > 0)
  362. _commandSupport_.fireCommandSent(command, message);
  363. __getReply();
  364. return _replyCode;
  365. }
  366. /***
  367. * Sends an FTP command to the server, waits for a reply and returns the
  368. * numerical response code. After invocation, for more detailed
  369. * information, the actual reply text can be accessed by calling
  370. * <a href="#getReplyString"> getReplyString </a> or
  371. * <a href="#getReplyStrings"> getReplyStrings </a>.
  372. * <p>
  373. * @param command The FTPCommand constant corresponding to the FTP command
  374. * to send.
  375. * @param args The arguments to the FTP command. If this parameter is
  376. * set to null, then the command is sent with no argument.
  377. * @return The integer value of the FTP reply code returned by the server
  378. * in response to the command.
  379. * @exception FTPConnectionClosedException
  380. * If the FTP server prematurely closes the connection as a result
  381. * of the client being idle or some other reason causing the server
  382. * to send FTP reply code 421. This exception may be caught either
  383. * as an IOException or independently as itself.
  384. * @exception IOException If an I/O error occurs while either sending the
  385. * command or receiving the server reply.
  386. ***/
  387. public int sendCommand(int command, String args) throws IOException
  388. {
  389. return sendCommand(FTPCommand._commands[command], args);
  390. }
  391. /***
  392. * Sends an FTP command with no arguments to the server, waits for a
  393. * reply and returns the numerical response code. After invocation, for
  394. * more detailed information, the actual reply text can be accessed by
  395. * calling <a href="#getReplyString"> getReplyString </a> or
  396. * <a href="#getReplyStrings"> getReplyStrings </a>.
  397. * <p>
  398. * @param command The text representation of the FTP command to send.
  399. * @return The integer value of the FTP reply code returned by the server
  400. * in response to the command.
  401. * @exception FTPConnectionClosedException
  402. * If the FTP server prematurely closes the connection as a result
  403. * of the client being idle or some other reason causing the server
  404. * to send FTP reply code 421. This exception may be caught either
  405. * as an IOException or independently as itself.
  406. * @exception IOException If an I/O error occurs while either sending the
  407. * command or receiving the server reply.
  408. ***/
  409. public int sendCommand(String command) throws IOException
  410. {
  411. return sendCommand(command, null);
  412. }
  413. /***
  414. * Sends an FTP command with no arguments to the server, waits for a
  415. * reply and returns the numerical response code. After invocation, for
  416. * more detailed information, the actual reply text can be accessed by
  417. * calling <a href="#getReplyString"> getReplyString </a> or
  418. * <a href="#getReplyStrings"> getReplyStrings </a>.
  419. * <p>
  420. * @param command The FTPCommand constant corresponding to the FTP command
  421. * to send.
  422. * @return The integer value of the FTP reply code returned by the server
  423. * in response to the command.
  424. * @exception FTPConnectionClosedException
  425. * If the FTP server prematurely closes the connection as a result
  426. * of the client being idle or some other reason causing the server
  427. * to send FTP reply code 421. This exception may be caught either
  428. * as an IOException or independently as itself.
  429. * @exception IOException If an I/O error occurs while either sending the
  430. * command or receiving the server reply.
  431. ***/
  432. public int sendCommand(int command) throws IOException
  433. {
  434. return sendCommand(command, null);
  435. }
  436. /***
  437. * Returns the integer value of the reply code of the last FTP reply.
  438. * You will usually only use this method after you connect to the
  439. * FTP server to check that the connection was successful since
  440. * <code> connect </code> is of type void.
  441. * <p>
  442. * @return The integer value of the reply code of the last FTP reply.
  443. ***/
  444. public int getReplyCode()
  445. {
  446. return _replyCode;
  447. }
  448. /***
  449. * Fetches a reply from the FTP server and returns the integer reply
  450. * code. After calling this method, the actual reply text can be accessed
  451. * from either calling <a href="#getReplyString"> getReplyString </a> or
  452. * <a href="#getReplyStrings"> getReplyStrings </a>. Only use this
  453. * method if you are implementing your own FTP client or if you need to
  454. * fetch a secondary response from the FTP server.
  455. * <p>
  456. * @return The integer value of the reply code of the fetched FTP reply.
  457. * @exception FTPConnectionClosedException
  458. * If the FTP server prematurely closes the connection as a result
  459. * of the client being idle or some other reason causing the server
  460. * to send FTP reply code 421. This exception may be caught either
  461. * as an IOException or independently as itself.
  462. * @exception IOException If an I/O error occurs while receiving the
  463. * server reply.
  464. ***/
  465. public int getReply() throws IOException
  466. {
  467. __getReply();
  468. return _replyCode;
  469. }
  470. /***
  471. * Returns the lines of text from the last FTP server response as an array
  472. * of strings, one entry per line. The end of line markers of each are
  473. * stripped from each line.
  474. * <p>
  475. * @return The lines of text from the last FTP response as an array.
  476. ***/
  477. public String[] getReplyStrings()
  478. {
  479. String[] lines;
  480. lines = new String[_replyLines.size()];
  481. _replyLines.copyInto(lines);
  482. return lines;
  483. }
  484. /***
  485. * Returns the entire text of the last FTP server response exactly
  486. * as it was received, including all end of line markers in NETASCII
  487. * format.
  488. * <p>
  489. * @return The entire text from the last FTP response as a String.
  490. ***/
  491. public String getReplyString()
  492. {
  493. Enumeration enum;
  494. StringBuffer buffer;
  495. if (!_newReplyString)
  496. return _replyString;
  497. buffer = new StringBuffer(256);
  498. enum = _replyLines.elements();
  499. while (enum.hasMoreElements())
  500. {
  501. buffer.append((String)enum.nextElement());
  502. buffer.append(SocketClient.NETASCII_EOL);
  503. }
  504. _newReplyString = false;
  505. return (_replyString = buffer.toString());
  506. }
  507. /***
  508. * A convenience method to send the FTP USER command to the server,
  509. * receive the reply, and return the reply code.
  510. * <p>
  511. * @param username The username to login under.
  512. * @return The reply code received from the server.
  513. * @exception FTPConnectionClosedException
  514. * If the FTP server prematurely closes the connection as a result
  515. * of the client being idle or some other reason causing the server
  516. * to send FTP reply code 421. This exception may be caught either
  517. * as an IOException or independently as itself.
  518. * @exception IOException If an I/O error occurs while either sending the
  519. * command or receiving the server reply.
  520. ***/
  521. public int user(String username) throws IOException
  522. {
  523. return sendCommand(FTPCommand.USER, username);
  524. }
  525. /**
  526. * A convenience method to send the FTP PASS command to the server,
  527. * receive the reply, and return the reply code.
  528. * @param password The plain text password of the username being logged into.
  529. * @return The reply code received from the server.
  530. * @exception FTPConnectionClosedException
  531. * If the FTP server prematurely closes the connection as a result
  532. * of the client being idle or some other reason causing the server
  533. * to send FTP reply code 421. This exception may be caught either
  534. * as an IOException or independently as itself.
  535. * @exception IOException If an I/O error occurs while either sending the
  536. * command or receiving the server reply.
  537. */
  538. public int pass(String password) throws IOException
  539. {
  540. return sendCommand(FTPCommand.PASS, password);
  541. }
  542. /***
  543. * A convenience method to send the FTP ACCT command to the server,
  544. * receive the reply, and return the reply code.
  545. * <p>
  546. * @param account The account name to access.
  547. * @return The reply code received from the server.
  548. * @exception FTPConnectionClosedException
  549. * If the FTP server prematurely closes the connection as a result
  550. * of the client being idle or some other reason causing the server
  551. * to send FTP reply code 421. This exception may be caught either
  552. * as an IOException or independently as itself.
  553. * @exception IOException If an I/O error occurs while either sending the
  554. * command or receiving the server reply.
  555. ***/
  556. public int acct(String account) throws IOException
  557. {
  558. return sendCommand(FTPCommand.ACCT, account);
  559. }
  560. /***
  561. * A convenience method to send the FTP ABOR command to the server,
  562. * receive the reply, and return the reply code.
  563. * <p>
  564. * @return The reply code received from the server.
  565. * @exception FTPConnectionClosedException
  566. * If the FTP server prematurely closes the connection as a result
  567. * of the client being idle or some other reason causing the server
  568. * to send FTP reply code 421. This exception may be caught either
  569. * as an IOException or independently as itself.
  570. * @exception IOException If an I/O error occurs while either sending the
  571. * command or receiving the server reply.
  572. ***/
  573. public int abor() throws IOException
  574. {
  575. return sendCommand(FTPCommand.ABOR);
  576. }
  577. /***
  578. * A convenience method to send the FTP CWD command to the server,
  579. * receive the reply, and return the reply code.
  580. * <p>
  581. * @param directory The new working directory.
  582. * @return The reply code received from the server.
  583. * @exception FTPConnectionClosedException
  584. * If the FTP server prematurely closes the connection as a result
  585. * of the client being idle or some other reason causing the server
  586. * to send FTP reply code 421. This exception may be caught either
  587. * as an IOException or independently as itself.
  588. * @exception IOException If an I/O error occurs while either sending the
  589. * command or receiving the server reply.
  590. ***/
  591. public int cwd(String directory) throws IOException
  592. {
  593. return sendCommand(FTPCommand.CWD, directory);
  594. }
  595. /***
  596. * A convenience method to send the FTP CDUP command to the server,
  597. * receive the reply, and return the reply code.
  598. * <p>
  599. * @return The reply code received from the server.
  600. * @exception FTPConnectionClosedException
  601. * If the FTP server prematurely closes the connection as a result
  602. * of the client being idle or some other reason causing the server
  603. * to send FTP reply code 421. This exception may be caught either
  604. * as an IOException or independently as itself.
  605. * @exception IOException If an I/O error occurs while either sending the
  606. * command or receiving the server reply.
  607. ***/
  608. public int cdup() throws IOException
  609. {
  610. return sendCommand(FTPCommand.CDUP);
  611. }
  612. /***
  613. * A convenience method to send the FTP QUIT command to the server,
  614. * receive the reply, and return the reply code.
  615. * <p>
  616. * @return The reply code received from the server.
  617. * @exception FTPConnectionClosedException
  618. * If the FTP server prematurely closes the connection as a result
  619. * of the client being idle or some other reason causing the server
  620. * to send FTP reply code 421. This exception may be caught either
  621. * as an IOException or independently as itself.
  622. * @exception IOException If an I/O error occurs while either sending the
  623. * command or receiving the server reply.
  624. ***/
  625. public int quit() throws IOException
  626. {
  627. return sendCommand(FTPCommand.QUIT);
  628. }
  629. /***
  630. * A convenience method to send the FTP REIN command to the server,
  631. * receive the reply, and return the reply code.
  632. * <p>
  633. * @return The reply code received from the server.
  634. * @exception FTPConnectionClosedException
  635. * If the FTP server prematurely closes the connection as a result
  636. * of the client being idle or some other reason causing the server
  637. * to send FTP reply code 421. This exception may be caught either
  638. * as an IOException or independently as itself.
  639. * @exception IOException If an I/O error occurs while either sending the
  640. * command or receiving the server reply.
  641. ***/
  642. public int rein() throws IOException
  643. {
  644. return sendCommand(FTPCommand.REIN);
  645. }
  646. /***
  647. * A convenience method to send the FTP SMNT command to the server,
  648. * receive the reply, and return the reply code.
  649. * <p>
  650. * @param dir The directory name.
  651. * @return The reply code received from the server.
  652. * @exception FTPConnectionClosedException
  653. * If the FTP server prematurely closes the connection as a result
  654. * of the client being idle or some other reason causing the server
  655. * to send FTP reply code 421. This exception may be caught either
  656. * as an IOException or independently as itself.
  657. * @exception IOException If an I/O error occurs while either sending the
  658. * command or receiving the server reply.
  659. ***/
  660. public int smnt(String dir) throws IOException
  661. {
  662. return sendCommand(FTPCommand.SMNT, dir);
  663. }
  664. /***
  665. * A convenience method to send the FTP PORT command to the server,
  666. * receive the reply, and return the reply code.
  667. * <p>
  668. * @param host The host owning the port.
  669. * @param port The new port.
  670. * @return The reply code received from the server.
  671. * @exception FTPConnectionClosedException
  672. * If the FTP server prematurely closes the connection as a result
  673. * of the client being idle or some other reason causing the server
  674. * to send FTP reply code 421. This exception may be caught either
  675. * as an IOException or independently as itself.
  676. * @exception IOException If an I/O error occurs while either sending the
  677. * command or receiving the server reply.
  678. ***/
  679. public int port(InetAddress host, int port) throws IOException
  680. {
  681. int num;
  682. StringBuffer info = new StringBuffer(24);
  683. info.append(host.getHostAddress().replace('.', ','));
  684. num = port >>> 8;
  685. info.append(',');
  686. info.append(num);
  687. info.append(',');
  688. num = port & 0xff;
  689. info.append(num);
  690. return sendCommand(FTPCommand.PORT, info.toString());
  691. }
  692. /***
  693. * A convenience method to send the FTP PASV command to the server,
  694. * receive the reply, and return the reply code. Remember, it's up
  695. * to you to interpret the reply string containing the host/port
  696. * information.
  697. * <p>
  698. * @return The reply code received from the server.
  699. * @exception FTPConnectionClosedException
  700. * If the FTP server prematurely closes the connection as a result
  701. * of the client being idle or some other reason causing the server
  702. * to send FTP reply code 421. This exception may be caught either
  703. * as an IOException or independently as itself.
  704. * @exception IOException If an I/O error occurs while either sending the
  705. * command or receiving the server reply.
  706. ***/
  707. public int pasv() throws IOException
  708. {
  709. return sendCommand(FTPCommand.PASV);
  710. }
  711. /**
  712. * A convenience method to send the FTP TYPE command for text files
  713. * to the server, receive the reply, and return the reply code.
  714. * @param fileType The type of the file (one of the <code>FILE_TYPE</code>
  715. * constants).
  716. * @param formatOrByteSize The format of the file (one of the
  717. * <code>_FORMAT</code> constants. In the case of
  718. * <code>LOCAL_FILE_TYPE</code>, the byte size.
  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 type(int fileType, int formatOrByteSize) throws IOException
  729. {
  730. StringBuffer arg = new StringBuffer();
  731. arg.append(__modes.charAt(fileType));
  732. arg.append(' ');
  733. if (fileType == LOCAL_FILE_TYPE)
  734. arg.append(formatOrByteSize);
  735. else
  736. arg.append(__modes.charAt(formatOrByteSize));
  737. return sendCommand(FTPCommand.TYPE, arg.toString());
  738. }
  739. /**
  740. * A convenience method to send the FTP TYPE command to the server,
  741. * receive the reply, and return the reply code.
  742. * <p>
  743. * @param fileType The type of the file (one of the <code>FILE_TYPE</code>
  744. * constants).
  745. * @return The reply code received from the server.
  746. * @exception FTPConnectionClosedException
  747. * If the FTP server prematurely closes the connection as a result
  748. * of the client being idle or some other reason causing the server
  749. * to send FTP reply code 421. This exception may be caught either
  750. * as an IOException or independently as itself.
  751. * @exception IOException If an I/O error occurs while either sending the
  752. * command or receiving the server reply.
  753. */
  754. public int type(int fileType) throws IOException
  755. {
  756. return sendCommand(FTPCommand.TYPE,
  757. __modes.substring(fileType, fileType + 1));
  758. }
  759. /***
  760. * A convenience method to send the FTP STRU command to the server,
  761. * receive the reply, and return the reply code.
  762. * <p>
  763. * @param structure The structure of the file (one of the
  764. * <code>_STRUCTURE</code> constants).
  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 stru(int structure) throws IOException
  775. {
  776. return sendCommand(FTPCommand.STRU,
  777. __modes.substring(structure, structure + 1));
  778. }
  779. /***
  780. * A convenience method to send the FTP MODE command to the server,
  781. * receive the reply, and return the reply code.
  782. * <p>
  783. * @param mode The transfer mode to use (one of the
  784. * <code>TRANSFER_MODE</code> constants).
  785. * @return The reply code received from the server.
  786. * @exception FTPConnectionClosedException
  787. * If the FTP server prematurely closes the connection as a result
  788. * of the client being idle or some other reason causing the server
  789. * to send FTP reply code 421. This exception may be caught either
  790. * as an IOException or independently as itself.
  791. * @exception IOException If an I/O error occurs while either sending the
  792. * command or receiving the server reply.
  793. ***/
  794. public int mode(int mode) throws IOException
  795. {
  796. return sendCommand(FTPCommand.MODE,
  797. __modes.substring(mode, mode + 1));
  798. }
  799. /***
  800. * A convenience method to send the FTP RETR command to the server,
  801. * receive the reply, and return the reply code. Remember, it is up
  802. * to you to manage the data connection. If you don't need this low
  803. * level of access, use <a href="org.apache.commons.net.ftp.FTPClient.html">
  804. * FTPClient</a>, which will handle all low level details for you.
  805. * <p>
  806. * @param pathname The pathname of the file to retrieve.
  807. * @return The reply code received from the server.
  808. * @exception FTPConnectionClosedException
  809. * If the FTP server prematurely closes the connection as a result
  810. * of the client being idle or some other reason causing the server
  811. * to send FTP reply code 421. This exception may be caught either
  812. * as an IOException or independently as itself.
  813. * @exception IOException If an I/O error occurs while either sending the
  814. * command or receiving the server reply.
  815. ***/
  816. public int retr(String pathname) throws IOException
  817. {
  818. return sendCommand(FTPCommand.RETR, pathname);
  819. }
  820. /***
  821. * A convenience method to send the FTP STOR command to the server,
  822. * receive the reply, and return the reply code. Remember, it is up
  823. * to you to manage the data connection. If you don't need this low
  824. * level of access, use <a href="org.apache.commons.net.ftp.FTPClient.html">
  825. * FTPClient</a>, which will handle all low level details for you.
  826. * <p>
  827. * @param pathname The pathname to use for the file when stored at
  828. * the remote end of the transfer.
  829. * @return The reply code received from the server.
  830. * @exception FTPConnectionClosedException
  831. * If the FTP server prematurely closes the connection as a result
  832. * of the client being idle or some other reason causing the server
  833. * to send FTP reply code 421. This exception may be caught either
  834. * as an IOException or independently as itself.
  835. * @exception IOException If an I/O error occurs while either sending the
  836. * command or receiving the server reply.
  837. ***/
  838. public int stor(String pathname) throws IOException
  839. {
  840. return sendCommand(FTPCommand.STOR, pathname);
  841. }
  842. /***
  843. * A convenience method to send the FTP STOU command to the server,
  844. * receive the reply, and return the reply code. Remember, it is up
  845. * to you to manage the data connection. If you don't need this low
  846. * level of access, use <a href="org.apache.commons.net.ftp.FTPClient.html">
  847. * FTPClient</a>, which will handle all low level details for you.
  848. * <p>
  849. * @return The reply code received from the server.
  850. * @exception FTPConnectionClosedException
  851. * If the FTP server prematurely closes the connection as a result
  852. * of the client being idle or some other reason causing the server
  853. * to send FTP reply code 421. This exception may be caught either
  854. * as an IOException or independently as itself.
  855. * @exception IOException If an I/O error occurs while either sending the
  856. * command or receiving the server reply.
  857. ***/
  858. public int stou() throws IOException
  859. {
  860. return sendCommand(FTPCommand.STOU);
  861. }
  862. /***
  863. * A convenience method to send the FTP STOU command to the server,
  864. * receive the reply, and return the reply code. Remember, it is up
  865. * to you to manage the data connection. If you don't need this low
  866. * level of access, use <a href="org.apache.commons.net.ftp.FTPClient.html">
  867. * FTPClient</a>, which will handle all low level details for you.
  868. * @param pathname The base pathname to use for the file when stored at
  869. * the remote end of the transfer. Some FTP servers
  870. * require this.
  871. * @return The reply code received from the server.
  872. * @exception FTPConnectionClosedException
  873. * If the FTP server prematurely closes the connection as a result
  874. * of the client being idle or some other reason causing the server
  875. * to send FTP reply code 421. This exception may be caught either
  876. * as an IOException or independently as itself.
  877. * @exception IOException If an I/O error occurs while either sending the
  878. * command or receiving the server reply.
  879. */
  880. public int stou(String pathname) throws IOException
  881. {
  882. return sendCommand(FTPCommand.STOU, pathname);
  883. }
  884. /***
  885. * A convenience method to send the FTP APPE command to the server,
  886. * receive the reply, and return the reply code. Remember, it is up
  887. * to you to manage the data connection. If you don't need this low
  888. * level of access, use <a href="org.apache.commons.net.ftp.FTPClient.html">
  889. * FTPClient</a>, which will handle all low level details for you.
  890. * <p>
  891. * @param pathname The pathname to use for the file when stored at
  892. * the remote end of the transfer.
  893. * @return The reply code received from the server.
  894. * @exception FTPConnectionClosedException
  895. * If the FTP server prematurely closes the connection as a result
  896. * of the client being idle or some other reason causing the server
  897. * to send FTP reply code 421. This exception may be caught either
  898. * as an IOException or independently as itself.
  899. * @exception IOException If an I/O error occurs while either sending the
  900. * command or receiving the server reply.
  901. ***/
  902. public int appe(String pathname) throws IOException
  903. {
  904. return sendCommand(FTPCommand.APPE, pathname);
  905. }
  906. /***
  907. * A convenience method to send the FTP ALLO command to the server,
  908. * receive the reply, and return the reply code.
  909. * <p>
  910. * @param bytes The number of bytes to allocate.
  911. * @return The reply code received from the server.
  912. * @exception FTPConnectionClosedException
  913. * If the FTP server prematurely closes the connection as a result
  914. * of the client being idle or some other reason causing the server
  915. * to send FTP reply code 421. This exception may be caught either
  916. * as an IOException or independently as itself.
  917. * @exception IOException If an I/O error occurs while either sending the
  918. * command or receiving the server reply.
  919. ***/
  920. public int allo(int bytes) throws IOException
  921. {
  922. return sendCommand(FTPCommand.ALLO, Integer.toString(bytes));
  923. }
  924. /***
  925. * A convenience method to send the FTP ALLO command to the server,
  926. * receive the reply, and return the reply code.
  927. * <p>
  928. * @param bytes The number of bytes to allocate.
  929. * @param recordSize The size of a record.
  930. * @return The reply code received from the server.
  931. * @exception FTPConnectionClosedException
  932. * If the FTP server prematurely closes the connection as a result
  933. * of the client being idle or some other reason causing the server
  934. * to send FTP reply code 421. This exception may be caught either
  935. * as an IOException or independently as itself.
  936. * @exception IOException If an I/O error occurs while either sending the
  937. * command or receiving the server reply.
  938. ***/
  939. public int allo(int bytes, int recordSize) throws IOException
  940. {
  941. return sendCommand(FTPCommand.ALLO, Integer.toString(bytes) + " R " +
  942. Integer.toString(recordSize));
  943. }
  944. /***
  945. * A convenience method to send the FTP REST command to the server,
  946. * receive the reply, and return the reply code.
  947. * <p>
  948. * @param marker The marker at which to restart a transfer.
  949. * @return The reply code received from the server.
  950. * @exception FTPConnectionClosedException
  951. * If the FTP server prematurely closes the connection as a result
  952. * of the client being idle or some other reason causing the server
  953. * to send FTP reply code 421. This exception may be caught either
  954. * as an IOException or independently as itself.
  955. * @exception IOException If an I/O error occurs while either sending the
  956. * command or receiving the server reply.
  957. ***/
  958. public int rest(String marker) throws IOException
  959. {
  960. return sendCommand(FTPCommand.REST, marker);
  961. }
  962. /***
  963. * A convenience method to send the FTP RNFR command to the server,
  964. * receive the reply, and return the reply code.
  965. * <p>
  966. * @param pathname The pathname to rename from.
  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 rnfr(String pathname) throws IOException
  977. {
  978. return sendCommand(FTPCommand.RNFR, pathname);
  979. }
  980. /***
  981. * A convenience method to send the FTP RNTO command to the server,
  982. * receive the reply, and return the reply code.
  983. * <p>
  984. * @param pathname The pathname to rename to
  985. * @return The reply code received from the server.
  986. * @exception FTPConnectionClosedException
  987. * If the FTP server prematurely closes the connection as a result
  988. * of the client being idle or some other reason causing the server
  989. * to send FTP reply code 421. This exception may be caught either
  990. * as an IOException or independently as itself.
  991. * @exception IOException If an I/O error occurs while either sending the
  992. * command or receiving the server reply.
  993. ***/
  994. public int rnto(String pathname) throws IOException
  995. {
  996. return sendCommand(FTPCommand.RNTO, pathname);
  997. }
  998. /***
  999. * A convenience method to send the FTP DELE command to the server,
  1000. * receive the reply, and return the reply code.
  1001. * <p>
  1002. * @param pathname The pathname to delete.
  1003. * @return The reply code received from the server.
  1004. * @exception FTPConnectionClosedException
  1005. * If the FTP server prematurely closes the connection as a result
  1006. * of the client being idle or some other reason causing the server
  1007. * to send FTP reply code 421. This exception may be caught either
  1008. * as an IOException or independently as itself.
  1009. * @exception IOException If an I/O error occurs while either sending the
  1010. * command or receiving the server reply.
  1011. ***/
  1012. public int dele(String pathname) throws IOException
  1013. {
  1014. return sendCommand(FTPCommand.DELE, pathname);
  1015. }
  1016. /***
  1017. * A convenience method to send the FTP RMD command to the server,
  1018. * receive the reply, and return the reply code.
  1019. * <p>
  1020. * @param pathname The pathname of the directory to remove.
  1021. * @return The reply code received from the server.
  1022. * @exception FTPConnectionClosedException
  1023. * If the FTP server prematurely closes the connection as a result
  1024. * of the client being idle or some other reason causing the server
  1025. * to send FTP reply code 421. This exception may be caught either
  1026. * as an IOException or independently as itself.
  1027. * @exception IOException If an I/O error occurs while either sending the
  1028. * command or receiving the server reply.
  1029. ***/
  1030. public int rmd(String pathname) throws IOException
  1031. {
  1032. return sendCommand(FTPCommand.RMD, pathname);
  1033. }
  1034. /***
  1035. * A convenience method to send the FTP MKD command to the server,
  1036. * receive the reply, and return the reply code.
  1037. * <p>
  1038. * @param pathname The pathname of the new directory to create.
  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 mkd(String pathname) throws IOException
  1049. {
  1050. return sendCommand(FTPCommand.MKD, pathname);
  1051. }
  1052. /***
  1053. * A convenience method to send the FTP PWD command to the server,
  1054. * receive the reply, and return the reply code.
  1055. * <p>
  1056. * @return The reply code received from the server.
  1057. * @exception FTPConnectionClosedException
  1058. * If the FTP server prematurely closes the connection as a result
  1059. * of the client being idle or some other reason causing the server
  1060. * to send FTP reply code 421. This exception may be caught either
  1061. * as an IOException or independently as itself.
  1062. * @exception IOException If an I/O error occurs while either sending the
  1063. * command or receiving the server reply.
  1064. ***/
  1065. public int pwd() throws IOException
  1066. {
  1067. return sendCommand(FTPCommand.PWD);
  1068. }
  1069. /***
  1070. * A convenience method to send the FTP LIST command to the server,
  1071. * receive the reply, and return the reply code. Remember, it is up
  1072. * to you to manage the data connection. If you don't need this low
  1073. * level of access, use <a href="org.apache.commons.net.ftp.FTPClient.html">
  1074. * FTPClient</a>, which will handle all low level details for you.
  1075. * <p>
  1076. * @return The reply code received from the server.
  1077. * @exception FTPConnectionClosedException
  1078. * If the FTP server prematurely closes the connection as a result
  1079. * of the client being idle or some other reason causing the server
  1080. * to send FTP reply code 421. This exception may be caught either
  1081. * as an IOException or independently as itself.
  1082. * @exception IOException If an I/O error occurs while either sending the
  1083. * command or receiving the server reply.
  1084. ***/
  1085. public int list() throws IOException
  1086. {
  1087. return sendCommand(FTPCommand.LIST);
  1088. }
  1089. /***
  1090. * A convenience method to send the FTP LIST command to the server,
  1091. * receive the reply, and return the reply code. Remember, it is up
  1092. * to you to manage the data connection. If you don't need this low
  1093. * level of access, use <a href="org.apache.commons.net.ftp.FTPClient.html">
  1094. * FTPClient</a>, which will handle all low level details for you.
  1095. * <p>
  1096. * @param pathname The pathname to list.
  1097. * @return The reply code received from the server.
  1098. * @exception FTPConnectionClosedException
  1099. * If the FTP server prematurely closes the connection as a result
  1100. * of the client being idle or some other reason causing the server
  1101. * to send FTP reply code 421. This exception may be caught either
  1102. * as an IOException or independently as itself.
  1103. * @exception IOException If an I/O error occurs while either sending the
  1104. * command or receiving the server reply.
  1105. ***/
  1106. public int list(String pathname) throws IOException
  1107. {
  1108. return sendCommand(FTPCommand.LIST, pathname);
  1109. }
  1110. /***
  1111. * A convenience method to send the FTP NLST command to the server,
  1112. * receive the reply, and return the reply code. Remember, it is up
  1113. * to you to manage the data connection. If you don't need this low
  1114. * level of access, use <a href="org.apache.commons.net.ftp.FTPClient.html">
  1115. * FTPClient</a>, which will handle all low level details for you.
  1116. * <p>
  1117. * @return The reply code received from the server.
  1118. * @exception FTPConnectionClosedException
  1119. * If the FTP server prematurely closes the connection as a result
  1120. * of the client being idle or some other reason causing the server
  1121. * to send FTP reply code 421. This exception may be caught either
  1122. * as an IOException or independently as itself.
  1123. * @exception IOException If an I/O error occurs while either sending the
  1124. * command or receiving the server reply.
  1125. ***/
  1126. public int nlst() throws IOException
  1127. {
  1128. return sendCommand(FTPCommand.NLST);
  1129. }
  1130. /***
  1131. * A convenience method to send the FTP NLST 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 <a href="org.apache.commons.net.ftp.FTPClient.html">
  1135. * FTPClient</a>, which will handle all low level details for you.
  1136. * <p>
  1137. * @param pathname The pathname to list.
  1138. * @return The reply code received from the server.
  1139. * @exception FTPConnectionClosedException
  1140. * If the FTP server prematurely closes the connection as a result
  1141. * of the client being idle or some other reason causing the server
  1142. * to send FTP reply code 421. This exception may be caught either
  1143. * as an IOException or independently as itself.
  1144. * @exception IOException If an I/O error occurs while either sending the
  1145. * command or receiving the server reply.
  1146. ***/
  1147. public int nlst(String pathname) throws IOException
  1148. {
  1149. return sendCommand(FTPCommand.NLST, pathname);
  1150. }
  1151. /***
  1152. * A convenience method to send the FTP SITE command to the server,
  1153. * receive the reply, and return the reply code.
  1154. * <p>
  1155. * @param parameters The site parameters to send.
  1156. * @return The reply code received from the server.
  1157. * @exception FTPConnectionClosedException
  1158. * If the FTP server prematurely closes the connection as a result
  1159. * of the client being idle or some other reason causing the server
  1160. * to send FTP reply code 421. This exception may be caught either
  1161. * as an IOException or independently as itself.
  1162. * @exception IOException If an I/O error occurs while either sending the
  1163. * command or receiving the server reply.
  1164. ***/
  1165. public int site(String parameters) throws IOException
  1166. {
  1167. return sendCommand(FTPCommand.SITE, parameters);
  1168. }
  1169. /***
  1170. * A convenience method to send the FTP SYST command to the server,
  1171. * receive the reply, and return the reply code.
  1172. * <p>
  1173. * @return The reply code received from the server.
  1174. * @exception FTPConnectionClosedException
  1175. * If the FTP server prematurely closes the connection as a result
  1176. * of the client being idle or some other reason causing the server
  1177. * to send FTP reply code 421. This exception may be caught either
  1178. * as an IOException or independently as itself.
  1179. * @exception IOException If an I/O error occurs while either sending the
  1180. * command or receiving the server reply.
  1181. ***/
  1182. public int syst() throws IOException
  1183. {
  1184. return sendCommand(FTPCommand.SYST);
  1185. }
  1186. /***
  1187. * A convenience method to send the FTP STAT command to the server,
  1188. * receive the reply, and return the reply code.
  1189. * <p>
  1190. * @return The reply code received from the server.
  1191. * @exception FTPConnectionClosedException
  1192. * If the FTP server prematurely closes the connection as a result
  1193. * of the client being idle or some other reason causing the server
  1194. * to send FTP reply code 421. This exception may be caught either
  1195. * as an IOException or independently as itself.
  1196. * @exception IOException If an I/O error occurs while either sending the
  1197. * command or receiving the server reply.
  1198. ***/
  1199. public int stat() throws IOException
  1200. {
  1201. return sendCommand(FTPCommand.STAT);
  1202. }
  1203. /***
  1204. * A convenience method to send the FTP STAT command to the server,
  1205. * receive the reply, and return the reply code.
  1206. * <p>
  1207. * @param pathname A pathname to list.
  1208. * @return The reply code received from the server.
  1209. * @exception FTPConnectionClosedException
  1210. * If the FTP server prematurely closes the connection as a result
  1211. * of the client being idle or some other reason causing the server
  1212. * to send FTP reply code 421. This exception may be caught either
  1213. * as an IOException or independently as itself.
  1214. * @exception IOException If an I/O error occurs while either sending the
  1215. * command or receiving the server reply.
  1216. ***/
  1217. public int stat(String pathname) throws IOException
  1218. {
  1219. return sendCommand(FTPCommand.STAT, pathname);
  1220. }
  1221. /***
  1222. * A convenience method to send the FTP HELP command to the server,
  1223. * receive the reply, and return the reply code.
  1224. * <p>
  1225. * @return The reply code received from the server.
  1226. * @exception FTPConnectionClosedException
  1227. * If the FTP server prematurely closes the connection as a result
  1228. * of the client being idle or some other reason causing the server
  1229. * to send FTP reply code 421. This exception may be caught either
  1230. * as an IOException or independently as itself.
  1231. * @exception IOException If an I/O error occurs while either sending the
  1232. * command or receiving the server reply.
  1233. ***/
  1234. public int help() throws IOException
  1235. {
  1236. return sendCommand(FTPCommand.HELP);
  1237. }
  1238. /***
  1239. * A convenience method to send the FTP HELP command to the server,
  1240. * receive the reply, and return the reply code.
  1241. * <p>
  1242. * @param command The command name on which to request help.
  1243. * @return The reply code received from the server.
  1244. * @exception FTPConnectionClosedException
  1245. * If the FTP server prematurely closes the connection as a result
  1246. * of the client being idle or some other reason causing the server
  1247. * to send FTP reply code 421. This exception may be caught either
  1248. * as an IOException or independently as itself.
  1249. * @exception IOException If an I/O error occurs while either sending the
  1250. * command or receiving the server reply.
  1251. ***/
  1252. public int help(String command) throws IOException
  1253. {
  1254. return sendCommand(FTPCommand.HELP, command);
  1255. }
  1256. /***
  1257. * A convenience method to send the FTP NOOP command to the server,
  1258. * receive the reply, and return the reply code.
  1259. * <p>
  1260. * @return The reply code received from the server.
  1261. * @exception FTPConnectionClosedException
  1262. * If the FTP server prematurely closes the connection as a result
  1263. * of the client being idle or some other reason causing the server
  1264. * to send FTP reply code 421. This exception may be caught either
  1265. * as an IOException or independently as itself.
  1266. * @exception IOException If an I/O error occurs while either sending the
  1267. * command or receiving the server reply.
  1268. ***/
  1269. public int noop() throws IOException
  1270. {
  1271. return sendCommand(FTPCommand.NOOP);
  1272. }
  1273. }