Skip to main content

download

Download a file from the server as a Uint8Array.
public async download(fileName: string): Promise<Uint8Array>

Parameters

fileName
string
required
The path to the file on the FTP server to download.

Return type

data
Promise<Uint8Array>
Returns a promise that resolves to the file contents as a Uint8Array.

Example

const fileData = await client.download('/path/to/file.txt');
const text = new TextDecoder().decode(fileData);
console.log(text);
This method automatically handles stream finalization. For more control over the download stream, use downloadReadable.

upload

Upload a file to the server.
public async upload(fileName: string, data: Uint8Array): Promise<void>

Parameters

fileName
string
required
The path where the file should be saved on the FTP server.
data
Uint8Array
required
The file contents to upload as a Uint8Array.

Return type

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

Example

const content = new TextEncoder().encode('Hello, World!');
await client.upload('/path/to/file.txt', content);
This method automatically handles stream finalization. For more control over the upload stream, use uploadWritable.

stat

Obtain detailed file information from the FTP server.
public async stat(filename: string): Promise<FTPFileInfo>

Parameters

filename
string
required
The path to the file or directory on the FTP server.

Return type

fileInfo
Promise<FTPFileInfo>
Returns a promise that resolves to an FTPFileInfo object containing file metadata.The FTPFileInfo object includes:
  • size: File size in bytes
  • mtime: Modification time
  • ctime: Creation time
  • isFile: Boolean indicating if this is a file
  • isDirectory: Boolean indicating if this is a directory
  • isSymlink: Boolean indicating if this is a symbolic link
  • ftpperms: FTP permissions string
  • mediaType: Media type if available
  • charset: Character set if available
  • Additional fields depending on server support

Example

const info = await client.stat('/path/to/file.txt');
console.log(`File size: ${info.size} bytes`);
console.log(`Modified: ${info.mtime}`);
console.log(`Is directory: ${info.isDirectory}`);
This method uses MLST command if supported by the server, otherwise falls back to SIZE and MDTM commands.

size

Get the size of a file in bytes.
public async size(filename: string): Promise<number>

Parameters

filename
string
required
The path to the file on the FTP server.

Return type

size
Promise<number>
Returns a promise that resolves to the file size in bytes.

Example

const fileSize = await client.size('/path/to/file.txt');
console.log(`File size: ${fileSize} bytes`);

modified

Get the last modification time of a file.
public async modified(filename: string): Promise<Date>

Parameters

filename
string
required
The path to the file on the FTP server.

Return type

modifiedDate
Promise<Date>
Returns a promise that resolves to a Date object representing the file’s last modification time.

Example

const modTime = await client.modified('/path/to/file.txt');
console.log(`Last modified: ${modTime.toISOString()}`);
This method requires the server to support the MDTM feature. An error is thrown if MDTM is not available.

rename

Rename a file on the server.
public async rename(from: string, to: string): Promise<boolean>

Parameters

from
string
required
The current path of the file on the FTP server.
to
string
required
The new path for the file on the FTP server.

Return type

success
Promise<boolean>
Returns a promise that resolves to true when the rename operation succeeds.

Example

await client.rename('/old/path/file.txt', '/new/path/file.txt');
console.log('File renamed successfully');

rm

Remove a file from the server.
public async rm(fileName: string): Promise<void>

Parameters

fileName
string
required
The path to the file to delete on the FTP server.

Return type

void
Promise<void>
Returns a promise that resolves when the file is successfully deleted.

Example

await client.rm('/path/to/file.txt');
console.log('File deleted');
This operation is permanent and cannot be undone. Make sure you want to delete the file before calling this method.

Build docs developers (and LLMs) love