- Client
- Event: 'abort'
- Event: 'connected'
- Event: 'disconnected'
- Event: 'progress'
- client.abort()
- client.config
- client.connect(config)
- client.connected
- client.createBlank(type, [, path][, files])
- client.delete(path)
- client.disconnect()
- client.download(path, dest, [, options])
- client.exists(path)
- client.mkdir(path)
- client.move(srcPath, destPath)
- client.pwd()
- client.readDir([, path])
- client.rimraf(path)
- client.send(command)
- client.size(path)
- client.stat(path)
- client.touch(path)
- client.unlink(path)
- client.upload(path, source, [, options])
An API, which provides access to FTP/FTPS/SFTP servers. It handles every method in a single queue.
context
Client
Emitted when the client.abort() has been called and before any reconnection is requested.
context
Client
Emitted when client has connected to a server.
context
Client
Emitted when client has disconnected from a server.
progress
ITransferProgressinfo
ITransferInfo
Emitted when a chunk of a file has been sent to a server. You can access information like transfer speed or eta in progress
. Basic file information, for example size and remote path in info
.
const client = new Client();
client.on('progress', (progress, info) => {
if (info.type === 'download') {
console.log(
`${info.remotePath} => ${info.localPath} - ${progress.eta} seconds left`,
);
}
});
- Returns: Promise<void>
Emits the abort
event.
Then stops the current file transfer by reconnecting to a server, using the same config provided with the client.connect().
config
IConfig- Returns: Promise<void>
Chooses which library to use, depending on the protocol provided in the config
. Connects to a server and then the connected
event is fired.
- Boolean
Indicates if client is connected to a server.
type
'folder' | 'file'path
String (optional)files
IFile[] (optional)- Returns: Promise<string>
Creates an empty file or folder at path
with an unique name. If you don't provide the files
arg, it will fetch automatically. Returns name of the file.
const client = new Client();
const name = await client.createBlank('file', '/documents');
console.log(`Name: ${name}`); // Name: new file
path
String- Returns: Promise<void>
Removes any files and folders at path
.
- Returns: Promise<void>
Aborts the current file transfer, if any. Then after client has disconnected from a server, the disconnected
event is fired.
path
Stringdest
stream.Writableoptions
ITransferOptions (optional)- Returns: Promise<ITransferStatus>
Downloads a remote file. Pipes data into dest
. When a new chunk of a file has been sent, the progress
event is fired.
You can start at a given offset by setting options
, which can be used to resume a transfer. Returns status of the transfer.
import { resolve } from 'path';
const client = new Client();
const remotePath = '/documents/new file.txt';
const localPath = resolve('downloads', 'new file.txt');
const status = await client.download(
remotePath,
createWriteStream(localPath, { flags: 'a' }),
{ startAt: 24000 }, // It will start at 24000 bytes
);
console.log(status); // finished
path
String- Returns: Promise<boolean>
Checks if file at path
exists.
const client = new Client();
const exists = await client.exists('/documents/new file.txt');
console.log(exists ? 'does exists!' : "doesn't exists!");
path
String- Returns: Promise<void>
Creates a new folder at path
.
srcPath
StringdestPath
String- Returns: Promise<void>
Moves a file from srcPath
to destPath
. Can be used to rename a file.
- Returns: Promise<string>
Returns path of the current working directory.
path
String (optional)- Returns: Promise<IFile[]>
Lists files and folders at path
.
path
string- Returns: Promise<void>
Deletes any file and folder at path
.
command
String- Returns: Promise<string>
Sends a raw command to a server and returns the response.
path
String- Returns: Promise<number>
Returns size of the file at path
in bytes.
path
String- Returns: Promise<IStats>
Returns details about the file at path
.
path
String- Returns: Promise<void>
Creates an empty file at path
.
path
String- Returns: Promise<void>
Deletes a single file (not a folder) at path
.
path
Stringsource
stream.Readableoptions
ITransferOptions- Returns: Promise<ITransferStatus>
Uploads a local file. When a new chunk of a file has been sent, the progress
event is fired. Returns status of the transfer.
import { resolve } from 'path';
const client = new Client();
const localPath = resolve('uploads', 'new file.txt');
const remotePath = '/documents/new file.txt';
const status = await client.upload(remotePath, createReadStream(localPath));
console.log(status); // finished