1 16 package org.apache.commons.net.ftp; 17 import java.io.BufferedInputStream ; 18 import java.io.BufferedOutputStream ; 19 import java.io.BufferedReader ; 20 import java.io.IOException ; 21 import java.io.InputStream ; 22 import java.io.InputStreamReader ; 23 import java.io.OutputStream ; 24 import java.net.InetAddress ; 25 import java.net.ServerSocket ; 26 import java.net.Socket ; 27 import java.util.Vector ; 28 29 import org.apache.commons.net.MalformedServerReplyException; 30 import org.apache.commons.net.ftp.parser.DefaultFTPFileEntryParserFactory; 31 import org.apache.commons.net.ftp.parser.FTPFileEntryParserFactory; 32 import org.apache.commons.net.ftp.parser.ParserInitializationException; 33 import org.apache.commons.net.io.CopyStreamEvent; 34 import org.apache.commons.net.io.CopyStreamException; 35 import org.apache.commons.net.io.FromNetASCIIInputStream; 36 import org.apache.commons.net.io.ToNetASCIIOutputStream; 37 import org.apache.commons.net.io.Util; 38 39 236 public class FTPClient extends FTP 237 implements Configurable 238 { 239 246 public static final int ACTIVE_LOCAL_DATA_CONNECTION_MODE = 0; 247 253 public static final int ACTIVE_REMOTE_DATA_CONNECTION_MODE = 1; 254 260 public static final int PASSIVE_LOCAL_DATA_CONNECTION_MODE = 2; 261 268 public static final int PASSIVE_REMOTE_DATA_CONNECTION_MODE = 3; 269 270 private int __dataConnectionMode, __dataTimeout; 271 private int __passivePort; 272 private String __passiveHost; 273 private int __fileType, __fileFormat, __fileStructure, __fileTransferMode; 274 private boolean __remoteVerificationEnabled; 275 private long __restartOffset; 276 private FTPFileEntryParserFactory __parserFactory; 277 private int __bufferSize; 278 279 private String __systemName; 282 283 private FTPFileEntryParser __entryParser; 286 287 private FTPClientConfig __configuration; 288 289 298 public FTPClient() 299 { 300 __initDefaults(); 301 __dataTimeout = -1; 302 __remoteVerificationEnabled = true; 303 __parserFactory = new DefaultFTPFileEntryParserFactory(); 304 __configuration = null; 305 } 306 307 308 private void __initDefaults() 309 { 310 __dataConnectionMode = ACTIVE_LOCAL_DATA_CONNECTION_MODE; 311 __passiveHost = null; 312 __passivePort = -1; 313 __fileType = FTP.ASCII_FILE_TYPE; 314 __fileStructure = FTP.FILE_STRUCTURE; 315 __fileFormat = FTP.NON_PRINT_TEXT_FORMAT; 316 __fileTransferMode = FTP.STREAM_TRANSFER_MODE; 317 __restartOffset = 0; 318 __systemName = null; 319 __entryParser = null; 320 __bufferSize = Util.DEFAULT_COPY_BUFFER_SIZE; 321 } 322 323 private String __parsePathname(String reply) 324 { 325 int begin, end; 326 327 begin = reply.indexOf('"') + 1; 328 end = reply.indexOf('"', begin); 329 330 return reply.substring(begin, end); 331 } 332 333 334 private void __parsePassiveModeReply(String reply) 335 throws MalformedServerReplyException 336 { 337 int i, index, lastIndex; 338 String octet1, octet2; 339 StringBuffer host; 340 341 reply = reply.substring(reply.indexOf('(') + 1, 342 reply.indexOf(')')).trim(); 343 344 host = new StringBuffer (24); 345 lastIndex = 0; 346 index = reply.indexOf(','); 347 host.append(reply.substring(lastIndex, index)); 348 349 for (i = 0; i < 3; i++) 350 { 351 host.append('.'); 352 lastIndex = index + 1; 353 index = reply.indexOf(',', lastIndex); 354 host.append(reply.substring(lastIndex, index)); 355 } 356 357 lastIndex = index + 1; 358 index = reply.indexOf(',', lastIndex); 359 360 octet1 = reply.substring(lastIndex, index); 361 octet2 = reply.substring(index + 1); 362 363 try 365 { 366 index = Integer.parseInt(octet1); 367 lastIndex = Integer.parseInt(octet2); 368 } 369 catch (NumberFormatException e) 370 { 371 throw new MalformedServerReplyException( 372 "Could not parse passive host information.\nServer Reply: " + reply); 373 } 374 375 index <<= 8; 376 index |= lastIndex; 377 378 __passiveHost = host.toString(); 379 __passivePort = index; 380 } 381 382 private boolean __storeFile(int command, String remote, InputStream local) 383 throws IOException 384 { 385 OutputStream output; 386 Socket socket; 387 388 if ((socket = _openDataConnection_(command, remote)) == null) 389 return false; 390 391 output = new BufferedOutputStream (socket.getOutputStream(), 392 getBufferSize() 393 ); 394 if (__fileType == ASCII_FILE_TYPE) 395 output = new ToNetASCIIOutputStream(output); 396 try 398 { 399 Util.copyStream(local, output, getBufferSize(), 400 CopyStreamEvent.UNKNOWN_STREAM_SIZE, null, 401 false); 402 } 403 catch (IOException e) 404 { 405 try 406 { 407 socket.close(); 408 } 409 catch (IOException f) 410 {} 411 throw e; 412 } 413 output.close(); 414 socket.close(); 415 return completePendingCommand(); 416 } 417 418 private OutputStream __storeFileStream(int command, String remote) 419 throws IOException 420 { 421 OutputStream output; 422 Socket socket; 423 424 if ((socket = _openDataConnection_(command, remote)) == null) 425 return null; 426 427 output = socket.getOutputStream(); 428 if (__fileType == ASCII_FILE_TYPE) { 429 output = new BufferedOutputStream (output, 437 getBufferSize()); 438 output = new ToNetASCIIOutputStream(output); 439 440 } 441 return new org.apache.commons.net.io.SocketOutputStream(socket, output); 442 } 443 444 445 463 protected Socket _openDataConnection_(int command, String arg) 464 throws IOException 465 { 466 Socket socket; 467 468 if (__dataConnectionMode != ACTIVE_LOCAL_DATA_CONNECTION_MODE && 469 __dataConnectionMode != PASSIVE_LOCAL_DATA_CONNECTION_MODE) 470 return null; 471 472 if (__dataConnectionMode == ACTIVE_LOCAL_DATA_CONNECTION_MODE) 473 { 474 ServerSocket server; 475 server = _socketFactory_.createServerSocket(0, 1, getLocalAddress()); 476 477 if (!FTPReply.isPositiveCompletion(port(getLocalAddress(), 478 server.getLocalPort()))) 479 { 480 server.close(); 481 return null; 482 } 483 484 if ((__restartOffset > 0) && !restart(__restartOffset)) 485 { 486 server.close(); 487 return null; 488 } 489 490 if (!FTPReply.isPositivePreliminary(sendCommand(command, arg))) 491 { 492 server.close(); 493 return null; 494 } 495 496 if (__dataTimeout >= 0) 501 server.setSoTimeout(__dataTimeout); 502 socket = server.accept(); 503 server.close(); 504 } 505 else 506 { 508 if (pasv() != FTPReply.ENTERING_PASSIVE_MODE) 509 return null; 510 511 __parsePassiveModeReply((String )_replyLines.elementAt(0)); 512 513 socket = _socketFactory_.createSocket(__passiveHost, __passivePort); 514 if ((__restartOffset > 0) && !restart(__restartOffset)) 515 { 516 socket.close(); 517 return null; 518 } 519 520 if (!FTPReply.isPositivePreliminary(sendCommand(command, arg))) 521 { 522 socket.close(); 523 return null; 524 } 525 } 526 527 if (__remoteVerificationEnabled && !verifyRemote(socket)) 528 { 529 InetAddress host1, host2; 530 531 host1 = socket.getInetAddress(); 532 host2 = getRemoteAddress(); 533 534 socket.close(); 535 536 throw new IOException ( 537 "Host attempting data connection " + host1.getHostAddress() + 538 " is not same as server " + host2.getHostAddress()); 539 } 540 541 if (__dataTimeout >= 0) 542 socket.setSoTimeout(__dataTimeout); 543 544 return socket; 545 } 546 547 548 protected void _connectAction_() throws IOException 549 { 550 super._connectAction_(); 551 __initDefaults(); 552 } 553 554 555 563 public void setDataTimeout(int timeout) 564 { 565 __dataTimeout = timeout; 566 } 567 568 577 public void setParserFactory(FTPFileEntryParserFactory parserFactory) { 578 __parserFactory = parserFactory; 579 } 580 581 582 588 public void disconnect() throws IOException 589 { 590 super.disconnect(); 591 __initDefaults(); 592 } 593 594 595 604 public void setRemoteVerificationEnabled(boolean enable) 605 { 606 __remoteVerificationEnabled = enable; 607 } 608 609 616 public boolean isRemoteVerificationEnabled() 617 { 618 return __remoteVerificationEnabled; 619 } 620 621 635 public boolean login(String username, String password) throws IOException 636 { 637 user(username); 638 639 if (FTPReply.isPositiveCompletion(_replyCode)) 640 return true; 641 642 if (!FTPReply.isPositiveIntermediate(_replyCode)) 645 return false; 646 647 return FTPReply.isPositiveCompletion(pass(password)); 648 } 649 650 651 668 public boolean login(String username, String password, String account) 669 throws IOException 670 { 671 user(username); 672 673 if (FTPReply.isPositiveCompletion(_replyCode)) 674 return true; 675 676 if (!FTPReply.isPositiveIntermediate(_replyCode)) 679 return false; 680 681 pass(password); 682 683 if (FTPReply.isPositiveCompletion(_replyCode)) 684 return true; 685 686 if (!FTPReply.isPositiveIntermediate(_replyCode)) 687 return false; 688 689 return FTPReply.isPositiveCompletion(acct(account)); 690 } 691 692 704 public boolean logout() throws IOException 705 { 706 return FTPReply.isPositiveCompletion(quit()); 707 } 708 709 710 723 public boolean changeWorkingDirectory(String pathname) throws IOException 724 { 725 return FTPReply.isPositiveCompletion(cwd(pathname)); 726 } 727 728 729 741 public boolean changeToParentDirectory() throws IOException 742 { 743 return FTPReply.isPositiveCompletion(cdup()); 744 } 745 746 747 760 public boolean structureMount(String pathname) throws IOException 761 { 762 return FTPReply.isPositiveCompletion(smnt(pathname)); 763 } 764 765 778 boolean reinitialize() throws IOException 779 { 780 rein(); 781 782 if (FTPReply.isPositiveCompletion(_replyCode) || 783 (FTPReply.isPositivePreliminary(_replyCode) && 784 FTPReply.isPositiveCompletion(getReply()))) 785 { 786 787 __initDefaults(); 788 789 return true; 790 } 791 792 return false; 793 } 794 795 796 805 public void enterLocalActiveMode() 806 { 807 __dataConnectionMode = ACTIVE_LOCAL_DATA_CONNECTION_MODE; 808 __passiveHost = null; 809 __passivePort = -1; 810 } 811 812 813 825 public void enterLocalPassiveMode() 826 { 827 __dataConnectionMode = PASSIVE_LOCAL_DATA_CONNECTION_MODE; 828 __passiveHost = null; 831 __passivePort = -1; 832 } 833 834 835 859 public boolean enterRemoteActiveMode(InetAddress host, int port) 860 throws IOException 861 { 862 if (FTPReply.isPositiveCompletion(port(host, port))) 863 { 864 __dataConnectionMode = ACTIVE_REMOTE_DATA_CONNECTION_MODE; 865 __passiveHost = null; 866 __passivePort = -1; 867 return true; 868 } 869 return false; 870 } 871 872 894 public boolean enterRemotePassiveMode() throws IOException 895 { 896 if (pasv() != FTPReply.ENTERING_PASSIVE_MODE) 897 return false; 898 899 __dataConnectionMode = PASSIVE_REMOTE_DATA_CONNECTION_MODE; 900 __parsePassiveModeReply((String )_replyLines.elementAt(0)); 901 902 return true; 903 } 904 905 917 public String getPassiveHost() 918 { 919 return __passiveHost; 920 } 921 922 934 public int getPassivePort() 935 { 936 return __passivePort; 937 } 938 939 940 947 public int getDataConnectionMode() 948 { 949 return __dataConnectionMode; 950 } 951 952 953 972 public boolean setFileType(int fileType) throws IOException 973 { 974 if (FTPReply.isPositiveCompletion(type(fileType))) 975 { 976 __fileType = fileType; 977 __fileFormat = FTP.NON_PRINT_TEXT_FORMAT; 978 return true; 979 } 980 return false; 981 } 982 983 984 1012 public boolean setFileType(int fileType, int formatOrByteSize) 1013 throws IOException 1014 { 1015 if (FTPReply.isPositiveCompletion(type(fileType, formatOrByteSize))) 1016 { 1017 __fileType = fileType; 1018 __fileFormat = formatOrByteSize; 1019 return true; 1020 } 1021 return false; 1022 } 1023 1024 1025 1040 public boolean setFileStructure(int structure) throws IOException 1041 { 1042 if (FTPReply.isPositiveCompletion(stru(structure))) 1043 { 1044 __fileStructure = structure; 1045 return true; 1046 } 1047 return false; 1048 } 1049 1050 1051 1066 public boolean setFileTransferMode(int mode) throws IOException 1067 { 1068 if (FTPReply.isPositiveCompletion(mode(mode))) 1069 { 1070 __fileTransferMode = mode; 1071 return true; 1072 } 1073 return false; 1074 } 1075 1076 1077 1092 public boolean remoteRetrieve(String filename) throws IOException 1093 { 1094 if (__dataConnectionMode == ACTIVE_REMOTE_DATA_CONNECTION_MODE || 1095 __dataConnectionMode == PASSIVE_REMOTE_DATA_CONNECTION_MODE) 1096 return FTPReply.isPositivePreliminary(retr(filename)); 1097 return false; 1098 } 1099 1100 1101 1118 public boolean remoteStore(String filename) throws IOException 1119 { 1120 if (__dataConnectionMode == ACTIVE_REMOTE_DATA_CONNECTION_MODE || 1121 __dataConnectionMode == PASSIVE_REMOTE_DATA_CONNECTION_MODE) 1122 return FTPReply.isPositivePreliminary(stor(filename)); 1123 return false; 1124 } 1125 1126 1127 1145 public boolean remoteStoreUnique(String filename) throws IOException 1146 { 1147 if (__dataConnectionMode == ACTIVE_REMOTE_DATA_CONNECTION_MODE || 1148 __dataConnectionMode == PASSIVE_REMOTE_DATA_CONNECTION_MODE) 1149 return FTPReply.isPositivePreliminary(stou(filename)); 1150 return false; 1151 } 1152 1153 1154 1172 public boolean remoteStoreUnique() throws IOException 1173 { 1174 if (__dataConnectionMode == ACTIVE_REMOTE_DATA_CONNECTION_MODE || 1175 __dataConnectionMode == PASSIVE_REMOTE_DATA_CONNECTION_MODE) 1176 return FTPReply.isPositivePreliminary(stou()); 1177 return false; 1178 } 1179 1180 1199 public boolean remoteAppend(String filename) throws IOException 1200 { 1201 if (__dataConnectionMode == ACTIVE_REMOTE_DATA_CONNECTION_MODE || 1202 __dataConnectionMode == PASSIVE_REMOTE_DATA_CONNECTION_MODE) 1203 return FTPReply.isPositivePreliminary(stor(filename)); 1204 return false; 1205 } 1206 1207 1251 public boolean completePendingCommand() throws IOException 1252 { 1253 return FTPReply.isPositiveCompletion(getReply()); 1254 } 1255 1256 1257 1279 public boolean retrieveFile(String remote, OutputStream local) 1280 throws IOException 1281 { 1282 InputStream input; 1283 Socket socket; 1284 1285 if ((socket = _openDataConnection_(FTPCommand.RETR, remote)) == null) 1286 return false; 1287 1288 input = new BufferedInputStream (socket.getInputStream(), 1289 getBufferSize()); 1290 if (__fileType == ASCII_FILE_TYPE) 1291 input = new FromNetASCIIInputStream(input); 1292 try 1294 { 1295 Util.copyStream(input, local, getBufferSize(), 1296 CopyStreamEvent.UNKNOWN_STREAM_SIZE, null, 1297 false); 1298 } 1299 catch (IOException e) 1300 { 1301 try 1302 { 1303 socket.close(); 1304 } 1305 catch (IOException f) 1306 {} 1307 throw e; 1308 } 1309 socket.close(); 1310 return completePendingCommand(); 1311 } 1312 1313 1337 public InputStream retrieveFileStream(String remote) throws IOException 1338 { 1339 InputStream input; 1340 Socket socket; 1341 1342 if ((socket = _openDataConnection_(FTPCommand.RETR, remote)) == null) 1343 return null; 1344 1345 input = socket.getInputStream(); 1346 if (__fileType == ASCII_FILE_TYPE) { 1347 input = new BufferedInputStream (input, 1355 getBufferSize()); 1356 input = new FromNetASCIIInputStream(input); 1357 } 1358 return new org.apache.commons.net.io.SocketInputStream(socket, input); 1359 } 1360 1361 1362 1385 public boolean storeFile(String remote, InputStream local) 1386 throws IOException 1387 { 1388 return __storeFile(FTPCommand.STOR, remote, local); 1389 } 1390 1391 1392 1417 public OutputStream storeFileStream(String remote) throws IOException 1418 { 1419 return __storeFileStream(FTPCommand.STOR, remote); 1420 } 1421 1422 1446 public boolean appendFile(String remote, InputStream local) 1447 throws IOException 1448 { 1449 return __storeFile(FTPCommand.APPE, remote, local); 1450 } 1451 1452 1477 public OutputStream appendFileStream(String remote) throws IOException 1478 { 1479 return __storeFileStream(FTPCommand.APPE, remote); 1480 } 1481 1482 1507 public boolean storeUniqueFile(String remote, InputStream local) 1508 throws IOException 1509 { 1510 return __storeFile(FTPCommand.STOU, remote, local); 1511 } 1512 1513 1514 1541 public OutputStream storeUniqueFileStream(String remote) throws IOException 1542 { 1543 return __storeFileStream(FTPCommand.STOU, remote); 1544 } 1545 1546 1569 public boolean storeUniqueFile(InputStream local) throws IOException 1570 { 1571 return __storeFile(FTPCommand.STOU, null, local); 1572 } 1573 1574 1599 public OutputStream storeUniqueFileStream() throws IOException 1600 { 1601 return __storeFileStream(FTPCommand.STOU, null); 1602 } 1603 1604 1617 public boolean allocate(int bytes) throws IOException 1618 { 1619 return FTPReply.isPositiveCompletion(allo(bytes)); 1620 } 1621 1622 1623 1637 public boolean allocate(int bytes, int recordSize) throws IOException 1638 { 1639 return FTPReply.isPositiveCompletion(allo(bytes, recordSize)); 1640 } 1641 1642 1643 1661 private boolean restart(long offset) throws IOException 1662 { 1663 __restartOffset = 0; 1664 return FTPReply.isPositiveIntermediate(rest(Long.toString(offset))); 1665 } 1666 1667 1676 public void setRestartOffset(long offset) 1677 { 1678 if (offset >= 0) 1679 __restartOffset = offset; 1680 } 1681 1682 1688 public long getRestartOffset() 1689 { 1690 return __restartOffset; 1691 } 1692 1693 1694 1695 1709 public boolean rename(String from, String to) throws IOException 1710 { 1711 if (!FTPReply.isPositiveIntermediate(rnfr(from))) 1712 return false; 1713 1714 return FTPReply.isPositiveCompletion(rnto(to)); 1715 } 1716 1717 1718 1730 public boolean abort() throws IOException 1731 { 1732 return FTPReply.isPositiveCompletion(abor()); 1733 } 1734 1735 1748 public boolean deleteFile(String pathname) throws IOException 1749 { 1750 return FTPReply.isPositiveCompletion(dele(pathname)); 1751 } 1752 1753 1754 1767 public boolean removeDirectory(String pathname) throws IOException 1768 { 1769 return FTPReply.isPositiveCompletion(rmd(pathname)); 1770 } 1771 1772 1773 1788 public boolean makeDirectory(String pathname) throws IOException 1789 { 1790 return FTPReply.isPositiveCompletion(mkd(pathname)); 1791 } 1792 1793 1794 1807 public String printWorkingDirectory() throws IOException 1808 { 1809 if (pwd() != FTPReply.PATHNAME_CREATED) 1810 return null; 1811 1812 return __parsePathname((String )_replyLines.elementAt(0)); 1813 } 1814 1815 1816 1828 public boolean sendSiteCommand(String arguments) throws IOException 1829 { 1830 return FTPReply.isPositiveCompletion(site(arguments)); 1831 } 1832 1833 1834 1852 public String getSystemName() throws IOException 1853 { 1854 if (__systemName == null && FTPReply.isPositiveCompletion(syst())) 1859 __systemName = ((String )_replyLines.elementAt(0)).substring(4); 1860 1861 return __systemName; 1862 } 1863 1864 1865 1879 public String listHelp() throws IOException 1880 { 1881 if (FTPReply.isPositiveCompletion(help())) 1882 return getReplyString(); 1883 return null; 1884 } 1885 1886 1887 1901 public String listHelp(String command) throws IOException 1902 { 1903 if (FTPReply.isPositiveCompletion(help(command))) 1904 return getReplyString(); 1905 return null; 1906 } 1907 1908 1909 1922 public boolean sendNoOp() throws IOException 1923 { 1924 return FTPReply.isPositiveCompletion(noop()); 1925 } 1926 1927 1928 1952 public String [] listNames(String pathname) throws IOException 1953 { 1954 String line; 1955 Socket socket; 1956 BufferedReader reader; 1957 Vector results; 1958 1959 if ((socket = _openDataConnection_(FTPCommand.NLST, pathname)) == null) 1960 return null; 1961 1962 reader = 1963 new BufferedReader (new InputStreamReader (socket.getInputStream(), getControlEncoding())); 1964 1965 results = new Vector (); 1966 while ((line = reader.readLine()) != null) 1967 results.addElement(line); 1968 reader.close(); 1969 socket.close(); 1970 1971 if (completePendingCommand()) 1972 { 1973 String [] result; 1974 result = new String [results.size()]; 1975 results.copyInto(result); 1976 return result; 1977 } 1978 1979 return null; 1980 } 1981 1982 1983 2004 public String [] listNames() throws IOException 2005 { 2006 return listNames(null); 2007 } 2008 2009 2010 2087 public FTPFile[] listFiles(String parserKey, String pathname) 2088 throws IOException 2089 { 2090 FTPListParseEngine engine = 2091 initiateListParsing(parserKey, pathname); 2092 return engine.getFiles(); 2093 } 2094 2095 2096 2137 public FTPFile[] listFiles(String pathname) 2138 throws IOException 2139 { 2140 String key = null; 2141 FTPListParseEngine engine = 2142 initiateListParsing(key, pathname); 2143 return engine.getFiles(); 2144 2145 } 2146 2185 public FTPFile[] listFiles() 2186 throws IOException 2187 { 2188 return listFiles((String ) null); 2189 } 2190 2191 2224 public FTPListParseEngine initiateListParsing() 2225 throws IOException 2226 { 2227 return initiateListParsing((String ) null); 2228 } 2229 2230 2279 public FTPListParseEngine initiateListParsing( 2280 String pathname) 2281 throws IOException 2282 { 2283 String key = null; 2284 return initiateListParsing(key, pathname); 2285 } 2286 2287 2335 public FTPListParseEngine initiateListParsing( 2336 String parserKey, String pathname) 2337 throws IOException 2338 { 2339 if(__entryParser == null) { 2342 if (null != parserKey) { 2343 __entryParser = 2346 __parserFactory.createFileEntryParser(parserKey); 2347 2348 } else { 2349 if (null != __configuration) { 2352 __entryParser = 2353 __parserFactory.createFileEntryParser(__configuration); 2354 } else { 2355 __entryParser = 2359 __parserFactory.createFileEntryParser(getSystemName()); 2360 } 2361 } 2362 } 2363 2364 return initiateListParsing(__entryParser, pathname); 2365 2366 } 2367 2368 2369 2383 private FTPListParseEngine initiateListParsing( 2384 FTPFileEntryParser parser, String pathname) 2385 throws IOException 2386 { 2387 Socket socket; 2388 2389 FTPListParseEngine engine = new FTPListParseEngine(parser); 2390 if ((socket = _openDataConnection_(FTPCommand.LIST, pathname)) == null) 2391 { 2392 return engine; 2393 } 2394 2395 2396 engine.readServerList(socket.getInputStream(), getControlEncoding()); 2397 2398 socket.close(); 2399 2400 completePendingCommand(); 2401 return engine; 2402 } 2403 2404 2416 public String getStatus() throws IOException 2417 { 2418 if (FTPReply.isPositiveCompletion(stat())) 2419 return getReplyString(); 2420 return null; 2421 } 2422 2423 2424 2437 public String getStatus(String pathname) throws IOException 2438 { 2439 if (FTPReply.isPositiveCompletion(stat(pathname))) 2440 return getReplyString(); 2441 return null; 2442 } 2443 2444 2482 public FTPFile[] listFiles(FTPFileListParser parser, String pathname) 2483 throws IOException 2484 { 2485 Socket socket; 2486 FTPFile[] results; 2487 2488 if ((socket = _openDataConnection_(FTPCommand.LIST, pathname)) == null) 2489 return new FTPFile[0]; 2490 2491 results = parser.parseFileList(socket.getInputStream(), getControlEncoding()); 2492 2493 socket.close(); 2494 2495 completePendingCommand(); 2496 2497 return results; 2498 } 2499 2500 2501 2530 public FTPFile[] listFiles(FTPFileListParser parser) throws IOException 2531 { 2532 return listFiles(parser, null); 2533 } 2534 2535 2536 2586 public FTPFileList createFileList(FTPFileEntryParser parser) throws IOException 2587 { 2588 return createFileList(null, parser); 2589 } 2590 2591 2622 public FTPFileList createFileList(String pathname, 2623 FTPFileEntryParser parser) 2624 throws IOException 2625 { 2626 Socket socket; 2627 2628 if ((socket = _openDataConnection_(FTPCommand.LIST, pathname)) == null) 2629 { 2630 return null; 2631 } 2632 2633 FTPFileList list = FTPFileList.create(socket.getInputStream(), parser); 2634 2635 socket.close(); 2636 2637 completePendingCommand(); 2638 return list; 2639 } 2640 2641 2646 public void setBufferSize(int bufSize) { 2647 __bufferSize = bufSize; 2648 } 2649 2650 2654 public int getBufferSize() { 2655 return __bufferSize; 2656 } 2657 2658 2659 2667 public void configure(FTPClientConfig config) { 2668 this.__configuration = config; 2669 } 2670 2671} 2672 2673 2680 | Popular Tags |