Skip to main content

List Directory

Lists the files in a directory on an FTP server.

Common Properties

  • Name - The custom name of the node.
  • Color - The custom color of the node.
  • Delay Before (sec) - Waits in seconds before executing the node.
  • Delay After (sec) - Waits in seconds after executing node.
  • Continue On Error - Automation will continue regardless of any error. The default value is false.
info

If the "Continue On Error" property is true, no error is caught when the project is executed even if a Catch node is used.

Input

  • Session Id - Id of the FTP session. The ID is the output of the Connect node.
  • Ftp Directory Path - Path of the directory whose files need to be listed

Output

  • Files - List of files in the specified FTP directory

Options

  • Sort - Specifies the sorting order of the list of files. The following options are available:
    • Name - Ascending
    • Name - Descending
    • Date - Last Modified
    • Date - Earliest Modified
  • Top - Specifies the maximum number of files to list in the output. The default value is 10.

How It Works

The List Directory node retrieves a listing of files and directories from the remote FTP server:

  1. Session Validation: Verifies the session ID is valid and active
  2. Path Validation: Ensures the directory path is not empty
  3. Directory Listing: Retrieves all files and subdirectories from the specified path
  4. Sorting: Applies the selected sort order (ascend, descend, modifiedlatest, modifiedearlier)
  5. Limit Application: Returns only the top N files if Top option is set
  6. Result Output: Returns an array of file objects with properties (Name, IsDir, Size, Date)

Requirements

  • Active FTP session from the Connect node
  • Valid directory path on the FTP server
  • Read/List permissions on the directory
  • Directory must exist on the server

Error Handling

Error CodeDescriptionCause
Core.FTP.ListDirectory.ErrOnCreateConfig parse errorNode configuration is malformed
Core.FTP.ListDir.ErrOnMessageMessage parse errorInput message cannot be parsed
Core.FTP.ListDirectory.ErrSessionSession id can not be emptySession ID input is empty
Core.FTP.ListDirectory.ErrSessionInvalid sessionSession ID does not exist or has expired
Core.FTP.ListDirectory.ErrPathPath can not be emptyDirectory path input is empty
Core.FTP.ListDirectory.SortInvalid sorting selectionSort option is not one of the valid values
Core.FTP.ListDirectory.ErrorList directory errorFailed to list directory (details in error message)

Usage Examples

Example 1: List All Files in Directory

// Input:
// Session ID: "ftp-session-123"
// FTP Directory Path: "/uploads"
// Sort: "Name - Ascending"
// Top: 0 (all files)
//
// Output:
// Files: [
// {Name: "file1.txt", IsDir: false, Size: 1024, Date: "2024-01-15T10:30:00Z"},
// {Name: "file2.pdf", IsDir: false, Size: 2048, Date: "2024-01-15T11:00:00Z"},
// {Name: "subfolder", IsDir: true, Size: 0, Date: "2024-01-14T09:00:00Z"}
// ]

Example 2: Get Latest 5 Files

// Input:
// Session ID: "ftp-session-123"
// FTP Directory Path: "/logs"
// Sort: "Date - Last Modified"
// Top: 5
//
// Returns only the 5 most recently modified files
// Useful for processing only new files

Example 3: Process Files in Loop

// Workflow:
// 1. List files in "/processing" directory
// 2. ForEach file in Files output:
// - If file.IsDir is false:
// - Download file
// - Process file
// - Move to "/completed" directory

Usage Examples (Advanced)

Filter and Download Specific Files

// After listing directory:
// Use Filter node to select only .csv files
// Then download each filtered file
msg.files.filter(f => f.Name.endsWith('.csv'))

Find Files Older Than N Days

// List directory with "Date - Earliest Modified"
// Filter files where Date is older than 30 days
// Delete old files to clean up space

Usage Notes

  • The output is an array of file objects, each containing Name, IsDir, Size, and Date properties
  • IsDir property is true for directories, false for files
  • Size is in bytes
  • Date is in ISO format (varies by FTP server)
  • Sort options: "ascend", "descend", "modifiedlatest", "modifiedearlier"
  • If Top is 0 or not set, all files are returned
  • The list includes both files and subdirectories
  • Hidden files may or may not be included depending on FTP server settings
  • Use forward slashes (/) in directory paths

Tips

  • Set Top to a reasonable number when listing large directories to improve performance
  • Use "Date - Last Modified" sort to find newest files quickly
  • Combine with ForEach loop to process multiple files
  • Filter the output array using conditions to select specific files
  • Store the file list in a variable for use in multiple subsequent operations
  • Use IsDir property to distinguish between files and directories
  • Check Size property to avoid processing empty files
  • Consider pagination for directories with thousands of files
  • Cache directory listings if checking multiple times in a workflow