001/* 002 * Version 0.70 01/04/2002 003 * 004 * Visit my url for update: http://www.geocities.com/beapetrovicova/ 005 * 006 * jFtp was developed by Bea Petrovicova <beapetrovicova@yahoo.com>. 007 * The design and implementation of jFtp are available for royalty-free 008 * adoption and use. This software is provided 'as is' without any 009 * guarantees. Copyright is retained by Bea Petrovicova. Redistribution 010 * of any part of jFtp or any derivative works must include this notice. 011 * 012 */ 013package cz.dhl.ftp; 014 015import java.io.IOException; 016 017/** 018 * Allows to list FTP directory. 019 * 020 * @Version 0.70 01/04/2002 021 * @author Bea Petrovicova <beapetrovicova@yahoo.com> 022 * @author Bea Petrovicova <beapetrovicova@yahoo.com> 023 */ 024final public class FtpListInputStream extends FtpInputStream 025{ 026 /** Open 'list' or 'name list' InputStream for given directory. 027 * <P><B>LIST</B> - list</P> 028 * <P>This command causes a list to be sent from the server to 029 * the passive DTP. If the pathname specifies a directory or 030 * other group of files, the server should transfer a list of 031 * files in the specified directory. If the pathname specifies 032 * a file then the server should send current information on 033 * the file. A null argument implies the user's current working 034 * or default directory. The data transfer is over the data 035 * connection in type ASCII. Since the information on a file 036 * may vary widely from system to system, this information may 037 * be hard to use automatically in a program, but may be quite 038 * useful to a human user.</P> 039 * <P><B>NLST</B> - name list</P> 040 * <P>This command causes a directory listing to be sent from 041 * server to user site. The pathname should specify a 042 * directory or other system-specific file group descriptor; 043 * a null argument implies the current directory. The server 044 * will return a stream of names of files and no other 045 * information. The data will be transferred in ASCII type 046 * over the data connection as valid pathname strings 047 * separated by [CRLF] or [NL]. This command is intended to 048 * return information that can be used by a program to further 049 * process the files automatically, for example in the 050 * implementation of a "multiple get" function.</P> 051 * @param dir directory to be listed 052 * @exception IOException socket error 053 * @exception FileNotFoundException server directory not found */ 054 public FtpListInputStream(FtpFile dir) throws IOException 055 { String command = null; 056 if(!dir.client.cd(dir.toString())) 057 throw new IOException("File: cd command failed!\ncd " +dir); 058 dir.path = dir.client.pwd(); 059 data=new FtpDataSocket(dir.client); 060 switch(data.context.getListCommandMode()) 061 { 062 case FtpContext.LIST: 063 command = "LIST"; break; 064 case FtpContext.NAME_LIST: 065 command = "NLST"; break; 066 case FtpContext.NAME_LIST_LS_F: 067 command = "NLST -F"; break; 068 case FtpContext.NAME_LIST_LS_P: 069 command = "NLST -p"; break; 070 case FtpContext.NAME_LIST_LS_LA: 071 command = "NLST -la"; break; 072 default: 073 throw new IOException("File: Invalid List Command Mode!"); 074 } 075 stream=data.getInputStream(command/* +dir*/, 'A'); 076 } 077}