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:
- Connects to the server using TCP sockets
- Discovers server features (FEAT command)
- Handles TLS handshake if secure mode is enabled
- Authenticates with username and password
- Switches to binary transfer mode
Return type
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
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.