public String[] listNames() throws IllegalStateException, IOException, FTPIllegalReplyException, FTPException, FTPDataTransferException, FTPAbortedException, FTPListParseException {
synchronized (lock) {
    if (!connected) {
      throw new IllegalStateException("Client not connected");
    }
    if (!authenticated) {
      throw new IllegalStateException("Client not authenticated");
    }
    communication.sendFTPCommand("TYPE A");
    FTPReply r=communication.readFTPReply();
    touchAutoNoopTimer();
    if (!r.isSuccessCode()) {
      throw new FTPException(r);
    }
    ArrayList lines=new ArrayList();
    boolean wasAborted=false;
    FTPDataTransferConnectionProvider provider=openDataTransferChannel();
    communication.sendFTPCommand("NLST");
    try {
      Socket dtConnection;
      try {
        dtConnection=provider.openDataTransferConnection();
      }
  finally {
        provider.dispose();
      }
synchronized (abortLock) {
        ongoingDataTransfer=true;
        aborted=false;
        consumeAborCommandReply=false;
      }
      NVTASCIIReader dataReader=null;
      try {
        dataTransferInputStream=dtConnection.getInputStream();
        if (modezEnabled) {
          dataTransferInputStream=new InflaterInputStream(dataTransferInputStream);
        }
        dataReader=new NVTASCIIReader(dataTransferInputStream,pickCharset());
        String line;
        while ((line=dataReader.readLine()) != null) {
          if (line.length() > 0) {
            lines.add(line);
          }
        }
      }
 catch (      IOException e) {
synchronized (abortLock) {
          if (aborted) {
            throw new FTPAbortedException();
          }
 else {
            throw new FTPDataTransferException("I/O error in data transfer",e);
          }
        }
      }
 finally {
        if (dataReader != null) {
          try {
            dataReader.close();
          }
 catch (          Throwable t) {
            ;
          }
        }
        try {
          dtConnection.close();
        }
 catch (        Throwable t) {
          ;
        }
        dataTransferInputStream=null;
synchronized (abortLock) {
          wasAborted=aborted;
          ongoingDataTransfer=false;
          aborted=false;
        }
      }
    }
  finally {
      r=communication.readFTPReply();
      if (r.getCode() != 150 && r.getCode() != 125) {
        throw new FTPException(r);
      }
      r=communication.readFTPReply();
      if (!wasAborted && r.getCode() != 226) {
        throw new FTPException(r);
      }
      if (consumeAborCommandReply) {
        communication.readFTPReply();
        consumeAborCommandReply=false;
      }
    }
    int size=lines.size();
    String[] list=new String[size];
    for (int i=0; i < size; i++) {
      list[i]=(String)lines.get(i);
    }
    return list;
  }
}

public String [ ] listNames ( ) throws IllegalStateException , IOException , FTPIllegalReplyException , FTPException , FTPDataTransferException , FTPAbortedException , FTPListParseException { synchronized ( lock ) { if ( ! connected ) { throw new IllegalStateException ( "Client not connected" ) ; } if ( ! authenticated ) { throw new IllegalStateException ( "Client not authenticated" ) ; } communication . sendFTPCommand ( "TYPE A" ) ; FTPReply r = communication . readFTPReply ( ) ; touchAutoNoopTimer ( ) ; if ( ! r . isSuccessCode ( ) ) { throw new FTPException ( r ) ; } ArrayList lines = new ArrayList ( ) ; boolean wasAborted = false ; FTPDataTransferConnectionProvider provider = openDataTransferChannel ( ) ; communication . sendFTPCommand ( "NLST" ) ; try { Socket dtConnection ; try { dtConnection = provider . openDataTransferConnection ( ) ; } finally { provider . dispose ( ) ; } synchronized ( abortLock ) { ongoingDataTransfer = true ; aborted = false ; consumeAborCommandReply = false ; } NVTASCIIReader dataReader = null ; try { dataTransferInputStream = dtConnection . getInputStream ( ) ; if ( modezEnabled ) { dataTransferInputStream = new InflaterInputStream ( dataTransferInputStream ) ; } dataReader = new NVTASCIIReader ( dataTransferInputStream , pickCharset ( ) ) ; String line ; while ( ( line = dataReader . readLine ( ) ) != null ) { if ( line . length ( ) > 0 ) { lines . add ( line ) ; } } } catch ( IOException e ) { synchronized ( abortLock ) { if ( aborted ) { throw new FTPAbortedException ( ) ; } else { throw new FTPDataTransferException ( "I/O error in data transfer" , e ) ; } } } finally { if ( dataReader != null ) { try { dataReader . close ( ) ; } catch ( Throwable t ) { ; } } try { dtConnection . close ( ) ; } catch ( Throwable t ) { ; } dataTransferInputStream = null ; synchronized ( abortLock ) { wasAborted = aborted ; ongoingDataTransfer = false ; aborted = false ; } } } finally { r = communication . readFTPReply ( ) ; if ( r . getCode ( ) != 150 && r . getCode ( ) != 125 ) { throw new FTPException ( r ) ; } r = communication . readFTPReply ( ) ; if ( ! wasAborted && r . getCode ( ) != 226 ) { throw new FTPException ( r ) ; } if ( consumeAborCommandReply ) { communication . readFTPReply ( ) ; consumeAborCommandReply = false ; } } int size = lines . size ( ) ; String [ ] list = new String [ size ] ; for ( int i = 0 ; i < size ; i ++ ) { list [ i ] = ( String ) lines . get ( i ) ; } return list ; } }
this method lists the entries of the current working directory with a ftp nlst command . the response consists in an array of string , each one reporting the name of a file or a directory placed in the current working directory . for a more detailed directory listing procedure look at the list ( ) method . calling this method blocks the current thread until the operation is completed . the operation could be interrupted by another thread calling abortcurrentdatatransfer ( ) . the listnames ( ) method will break with a ftpabortedexception .
