Skip to main content

connect

Initialize a connection to the FTP server.
public async connect(): Promise<void>
This method establishes a connection to the FTP server and performs the following operations:
  1. Connects to the server using TCP sockets
  2. Discovers server features (FEAT command)
  3. Handles TLS handshake if secure mode is enabled
  4. Authenticates with username and password
  5. Switches to binary transfer mode

Return type

void
Promise<void>
Returns a promise that resolves when the connection is fully established and authenticated.

Example

import { FTPClient } from 'workerd-ftp';

const client = new FTPClient('ftp.example.com', {
  user: 'username',
  pass: 'password',
  port: 21,
  secure: true
});

await client.connect();
The connect method must be called before using any other FTP operations.
If secure mode is enabled but the server doesn’t support TLS, a warning is logged and the connection attempts TLS anyway.

close

Close the connection to the FTP server and release all resources.
public async close(): Promise<void>
This method closes both the control connection and any active data connections, releasing all locks and cleaning up resources.

Return type

void
Promise<void>
Returns a promise that resolves when all connections are closed.

Example

import { FTPClient } from 'workerd-ftp';

const client = new FTPClient('ftp.example.com');
await client.connect();

// ... perform FTP operations ...

await client.close();
Always call close when you’re done to avoid loose connections and resource leaks.

Build docs developers (and LLMs) love