ftp-sftp-client
v1.0.11
Published
TypeScript NPM Module for ftp/sftp client
Maintainers
Readme
ftp-sftp-client
A unified TypeScript client for FTP and SFTP file operations with a consistent API across both protocols.
Installation
npm install ftp-sftp-clientUsage
Unified Client
Use Client to switch between FTP and SFTP with the same API:
const { Client } = require('ftp-sftp-client');
const client = new Client('sftp'); // or 'ftp'
await client.connect('hostname', 'username', 'password');
await client.uploadFile('./local/file.txt', '/remote/file.txt');
await client.end();Protocol-Specific Clients
const { FTPClient, SFTPClient } = require('ftp-sftp-client');
const ftp = new FTPClient();
await ftp.connect('hostname', 'username', 'password');
const sftp = new SFTPClient();
await sftp.connect('hostname', 'username', 'password');Accessing the Underlying Client
// Returns the underlying basic-ftp or ssh2-sftp-client instance
const rawClient = await client.getClient();API
| Method | Description |
|--------|-------------|
| connect(host, user, password) | Connect to server |
| getClient() | Get underlying protocol client |
| listDirectory(path, recursive?) | List files, optionally recursive |
| makeDirectory(path) | Create remote directory |
| moveRemoteFileOrDirectory(src, dest) | Move or rename remote file/directory |
| isRemoteDirectoryEmpty(path) | Check if directory is empty |
| deleteDirectoryIfEmpty(path) | Delete directory only if empty |
| fileExists(path) | Check if file exists |
| directoryExists(path) | Check if directory exists |
| pathExists(path) | Check if path exists (file or directory) |
| deleteFile(path) | Delete a file |
| deleteDirectory(path) | Delete a directory |
| uploadFile(local, remote) | Upload a single file |
| uploadDirectory(local, remote) | Upload a directory |
| downloadFile(remote, local) | Download a single file |
| downloadDirectory(remote, local) | Download a directory |
| pwd() | Get current working directory |
| end() | Close connection |
License
MIT
