Qusly-core is an API wrapper around ssh2 and basic-ftp for building FTP/FTPS/SFTP clients. It's used in Qusly.

Features
- Supports FTP, FTPS, SFTP
- Promises
- Lots of utilities like
createBlank
- Splited transfer
- Automatically calculates ETA and transfer speed
- MS-dos support
Checkout roadmap to see what's coming.
Installing
$ npm install qusly-core
Quick start
An example of listing files:
; { const client = ; await client; const files = await client; console; await client;} ;
Example output:
name: 'projects' type: 'directory' size: 4096 ext: '' user: 'root' group: 'root' date: '2019-05-10T18:52:00.000Z' // obj Date permissions: user: 6 group: 6 name: 'logs.txt' type: 'file' ext: 'txt' size: 43 user: 'root' group: 'root' date: '2019-05-29T22:00:00.000Z' // obj Date permissions: user: 6 group: 6
API
Class Client
:
Client.abort
Client.connect
Client.createBlank
Client.delete
Client.disconnect
Client.download
Client.exists
Client.mkdir
Client.move
Client.pwd
Client.readDir
Client.rimraf
Client.send
Client.size
Client.stat
Client.touch
Client.unlink
Client.upload
Class TransferClient
:
TransferClient
TransferClient.connect
TransferClient.getSplits
TransferClient.setSplits
TransferClient.transfer
Interfaces:
IConfig
IDownloadOptions
IFile
IProgress
IStats
ITransferClientNew
ITransferClientProgress
ITransferOptions
Types:
Events:
Client.on('abort')
Client.on('connect')
Client.on('disconnect')
Client.on('progress')
TransferClient.on('new')
TransferClient.on('progress')
Client
Class Methods
-
Client.abort(): Promise<void>
Aborts current data transfer. It closes all used file streams.const bytes = await client;console;
-
Client.connect(config: IConfig): Promise<void>
Connects to server. You can use it to reload session.tryawait client;console;catch errorconsole;
-
Client.createBlank(type: 'folder' | 'file', path = './', files?: IFile[]): Promise<string>
Creates an empty folder or file with unique name. If you've fetched files already, you can provide last argument to don't refetch files.const res = await client;console;
-
Client.delete(path: string): Promise<void>
An universal method to remove both files and folders.await client;console;
-
Client.disconnect(): Promise<void>
Disconnects from server. Closes all opened sockets and file streams.await client;console;
-
Client.download(path: string, dest: Writable, options?: IDownloadOptions): Promise<void>
Downloads a file. You can start at given offset by setting options tostartAt: 65536;
;;const localPath = ;client;await client;console;
-
Client.exists(path: string): Promise<boolean>
Checks if file exists.const exists = await client;if existsconsole;elseconsole;
-
Client.mkdir(path: string): Promise<void>
Creates a directory.await client;console;
-
Client.move(srcPath: string, destPath: string): Promise<void>
Moves a file fromsrcPath
todestPath
.await client;console;
-
Client.pwd(): Promise<IPwdRes>
Returns path of current working directory.const path = await client;console;
-
Client.readDir(path?: string): Promise<IFile[]>
Reads content of a directory. If you don't provide path, it'll use working directory.const files = await client;console;
-
Client.rimraf(path: string): Promise<void>
Removes a directory and all of its content, recursively.await client;console;
-
Client.send(command: string): Promise<string>
Sends a raw command. Output depends on a protocol and server support!// It'll probably work on SFTPconst res = await client;console;
-
Client.size(path: string): Promise<number>
Returns size of a file or folder in bytes.const size = await clientsize'file.rar';console;
-
Client.stat(path: string): Promise<IStats>
Returns info about file at given path.const res = await client;console;
-
Client.touch(path: string): Promise<IRes>
Creates an empty file.await client;console;
-
Client.unlink(path: string): Promise<IRes>
Removes a file atpath
.await client;console;
-
Client.upload(path: string, source: Readable, options?: ITransferOptions): Promise<void>
Uploads a file.;;const localPath = ;const fileSize = size;client;await client;console;
TransferClient
Class An utility class to split transfers.
Methods
TransferClient(type: ITransferType, splits = 1)
-
TransferClient.connect(config: IConfig): Promise<void>
Connects clients to server.await client;console;
TransferClient.getSplits(): number
Gets splits length.
-
TransferClient.setSplits(count: number, config?: IConfig): Promise<void>
Sets splits. If you're setting more than you had, you must provide config. If you're setting less than you had, it will automatically close rest of client.const client = 'download' 2;console; // 2await client;console; // 6await client;console; // 4
-
TransferClient.transfer(localPath: string, remotePath: string, id?: string): Promise<void>
Transfers a file. You can set your ownid
or it'll be unique hash. To track progress, use eventprogress
. With 2 splits, you can transfer files twice as fast.await client;await client;
IConfig
Interface
IDownloadOptions
Interface
IFile
Interface
IProgress
Interface
IStats
Interface
ITransferClientNew
Interface
ITransferClientProgress
Interface
ITransferOptions
Interface
IFileType
Type ;
IProtocol
Type ;
ITransferType
Type ;
Events
Client
Client.on('abort')
- File transfer has been aborted.
Client.on('connect')
- Client has connected to server.
Client.on('disconnect')
- Client has disconnected from server.
-
Client.on('progress', e: IProgress)
- Triggered while transfering a file.client.on'progress',;client.download...;
TransferClient
TransferClient.on('new', e: ITransferClientNew)
- Invoked on every new file transfer.
TransferClient.on('progress', e: ITransferClientProgress)
- Triggered while transfering a file. This event comes with a lot of information. Some of that are:- Id, which you can use to identify transfer.
- Type of transfer
ITransferType
- Single chunk size in bytes
- Buffered size
- File size
- Estimated time arrival in seconds
- Transfer speed in bytes/s
- Percent of buffered size
- Start time
client.on'progress',; client.transfer...;
Related
- Qusly - Elegant, full-featured FTP client.