static public List < String > listFilesInDirectory ( MuleContext muleContext , String endpointName ) { logger . info ( "List endpoint: {}" , endpointName ) ; FTPClient ftpClient = null ; List < String > fileNames = new ArrayList < String > ( ) ; try { ftpClient = getFtpClient ( muleContext , endpointName ) ; EndpointURI endpointURI = getImmutableEndpoint ( muleContext , endpointName ) . getEndpointURI ( ) ; String path = endpointURI . getPath ( ) ; logger . info ( "List directory: {}" , path ) ; FTPFile [ ] ftpFiles = ftpClient . listFiles ( path ) ; logger . debug ( "Number of files and sub-folders found: {}" , ftpFiles . length ) ; for ( FTPFile ftpFile : ftpFiles ) { if ( ftpFile . getType ( ) == FTPFile . FILE_TYPE ) { String filename = path + "/" + ftpFile . getName ( ) ; fileNames . add ( filename ) ; logger . debug ( "Added file {}" , filename ) ; } } logger . debug ( "Found {} files in {}" , fileNames . size ( ) , path ) ; } catch ( Exception e ) { if ( logger . isErrorEnabled ( ) ) logger . error ( "Failed to list files in endpoint " + endpointName , e ) ; throw new RuntimeException ( e ) ; } finally { if ( ftpClient != null ) { try { ftpClient . disconnect ( ) ; } catch ( IOException e ) { } } } return fileNames ; }
List files in a directory . Do not return sub - directories just plain files