List of usage examples for org.apache.commons.net.ftp FTPCmd NLST
FTPCmd NLST
To view the source code for org.apache.commons.net.ftp FTPCmd NLST.
Click Source Link
From source file:com.atomicleopard.thundr.ftp.commons.FTP.java
/*** * A convenience method to send the FTP NLST command to the server, * receive the reply, and return the reply code. Remember, it is up * to you to manage the data connection. If you don't need this low * level of access, use {@link org.apache.commons.net.ftp.FTPClient} * , which will handle all low level details for you. * <p>/* w w w .j ava 2s . c o m*/ * @return The reply code received from the server. * @exception FTPConnectionClosedException * If the FTP server prematurely closes the connection as a result * of the client being idle or some other reason causing the server * to send FTP reply code 421. This exception may be caught either * as an IOException or independently as itself. * @exception IOException If an I/O error occurs while either sending the * command or receiving the server reply. ***/ public int nlst() throws IOException { return sendCommand(FTPCmd.NLST); }
From source file:com.atomicleopard.thundr.ftp.commons.FTP.java
/*** * A convenience method to send the FTP NLST command to the server, * receive the reply, and return the reply code. Remember, it is up * to you to manage the data connection. If you don't need this low * level of access, use {@link org.apache.commons.net.ftp.FTPClient} * , which will handle all low level details for you. * <p>//www. ja v a 2 s . c om * @param pathname The pathname to list, * may be {@code null} in which case the command is sent with no parameters * @return The reply code received from the server. * @exception FTPConnectionClosedException * If the FTP server prematurely closes the connection as a result * of the client being idle or some other reason causing the server * to send FTP reply code 421. This exception may be caught either * as an IOException or independently as itself. * @exception IOException If an I/O error occurs while either sending the * command or receiving the server reply. ***/ public int nlst(String pathname) throws IOException { return sendCommand(FTPCmd.NLST, pathname); }
From source file:com.atomicleopard.thundr.ftp.commons.FTPClient.java
/** * Obtain a list of filenames in a directory (or just the name of a given * file, which is not particularly useful). This information is obtained * through the NLST command. If the given pathname is a directory and * contains no files, a zero length array is returned only * if the FTP server returned a positive completion code, otherwise * null is returned (the FTP server returned a 550 error No files found.). * If the directory is not empty, an array of filenames in the directory is * returned. If the pathname corresponds * to a file, only that file will be listed. The server may or may not * expand glob expressions./*from ww w. j a va 2 s . c o m*/ * <p> * @param pathname The file or directory to list. * Warning: the server may treat a leading '-' as an * option introducer. If so, try using an absolute path, * or prefix the path with ./ (unix style servers). * Some servers may support "--" as meaning end of options, * in which case "-- -xyz" should work. * @return The list of filenames contained in the given path. null if * the list could not be obtained. If there are no filenames in * the directory, a zero-length array is returned. * @exception FTPConnectionClosedException * If the FTP server prematurely closes the connection as a result * of the client being idle or some other reason causing the server * to send FTP reply code 421. This exception may be caught either * as an IOException or independently as itself. * @exception IOException If an I/O error occurs while either sending a * command to the server or receiving a reply from the server. */ public String[] listNames(String pathname) throws IOException { Socket socket = _openDataConnection_(FTPCmd.NLST, getListArguments(pathname)); if (socket == null) { return null; } BufferedReader reader = new BufferedReader( new InputStreamReader(socket.getInputStream(), getControlEncoding())); ArrayList<String> results = new ArrayList<String>(); String line; while ((line = reader.readLine()) != null) { results.add(line); } reader.close(); socket.close(); if (completePendingCommand()) { String[] names = new String[results.size()]; return results.toArray(names); } return null; }