Skip to main content

list

Retrieve a plain directory listing from the server.
public async list(dirName?: string): Promise<string[]>

Parameters

dirName
string
The directory path to list. If not provided, lists the current working directory.

Return type

listing
Promise<string[]>
Returns a promise that resolves to an array of strings, where each string represents a file or directory entry in plain text format.

Example

const files = await client.list('/home/user');
files.forEach(file => console.log(file));

// List current directory
const currentDir = await client.list();
This method uses the NLST command. For structured data with file metadata, use extendedList instead.

extendedList

Retrieve a detailed directory listing with file metadata.
public async extendedList(dirName?: string): Promise<Array<[string, FTPFileInfo]>>

Parameters

dirName
string
The directory path to list. If not provided, lists the current working directory.

Return type

listing
Promise<Array<[string, FTPFileInfo]>>
Returns a promise that resolves to an array of tuples. Each tuple contains:
  • First element: filename (string)
  • Second element: FTPFileInfo object with metadata (size, modification time, permissions, etc.)

Example

const entries = await client.extendedList('/home/user');

for (const [filename, info] of entries) {
  console.log(`${filename}: ${info.size} bytes, ${info.isDirectory ? 'dir' : 'file'}`);
  console.log(`  Modified: ${info.mtime}`);
}
This method uses the MLSD command which provides structured machine-readable directory listings.

mkdir

Create a new directory on the server.
public async mkdir(dirName: string): Promise<boolean>

Parameters

dirName
string
required
The path of the directory to create on the FTP server.

Return type

success
Promise<boolean>
Returns a promise that resolves to true when the directory is successfully created.

Example

await client.mkdir('/home/user/newdir');
console.log('Directory created');

rmdir

Remove a directory from the server.
public async rmdir(dirName: string): Promise<void>

Parameters

dirName
string
required
The path of the directory to remove from the FTP server.

Return type

void
Promise<void>
Returns a promise that resolves when the directory is successfully removed.

Example

await client.rmdir('/home/user/olddir');
console.log('Directory removed');
Most FTP servers require the directory to be empty before it can be removed.

chdir

Change the current working directory.
public async chdir(path: string): Promise<void>

Parameters

path
string
required
The directory path to change to on the FTP server.

Return type

void
Promise<void>
Returns a promise that resolves when the directory change is complete.

Example

await client.chdir('/home/user/documents');
console.log('Changed to documents directory');

// You can now perform operations relative to this directory
const files = await client.list();
This is equivalent to the Unix cd command. All subsequent operations will be relative to the new directory.

cwd

Get the current working directory path.
public async cwd(): Promise<string>

Return type

path
Promise<string>
Returns a promise that resolves to a string containing the absolute path of the current working directory.

Example

const currentPath = await client.cwd();
console.log(`Current directory: ${currentPath}`);
This is equivalent to the Unix pwd command.

cdup

Change to the parent directory.
public async cdup(): Promise<void>

Return type

void
Promise<void>
Returns a promise that resolves when the directory change is complete.

Example

// Move up one directory level
await client.cdup();

const currentPath = await client.cwd();
console.log(`Now in: ${currentPath}`);
This is equivalent to the Unix command cd ..

Build docs developers (and LLMs) love