rx-node-ftp-client
Description
rx-node-ftp-client is an observable version of the package ftp-client - with some improvements.
Requirements
- node.js -- v0.8.0 or newer
- npm -- v2.0.0 or newer
Dependencies
Installation
npm install rx-node-ftp-client
Usage
Initialization
To create an instance of the FTP client object:
TypeScript:
;ftpClient = new Clientconfig, options;
where config
contains the ftp server configuration (these are the default values):
host: 'localhost' port: 21 user: 'anonymous' password: 'anonymous@'
(To check more options, see the ftp npm package)
and the options
object may contain the following keys:
- logging (String):
'none'
,'basic'
,'debug'
- level of logging for all the tasks - use'debug'
in case of any issues - Logger (Console): default
console
- if you want to inject your custom logger, use this property - overwrite (String):
'none'
,'older'
,'all'
- determines which files should be overwritten when downloading/uploading -'older'
compares the date of modification of local and remote files - testingTimezoneDir (String): default
null
- using default home directory ifnull
. The directory should have Read/Write permission in order to adjust timezone for overwriting files. - globOptions (Glob configuraion object): default
{ nonull: false }
- Custom glob options for file search. - disconnect (boolean): default
true
- disconnect from ftp after an upload or download operation.
Connecting
After creating the new object you have to manually connect to the server by using the connect
method:
ftpClient.connect.subscribeconsole.log'Connected', console.errorerr,,;
Disconnected
If you choose the option of manually disconnect from the server, you have to use the disconnect
method:
ftpClient.disconnect.subscribeconsole.log'Disconnected', console.errorerr,,;
Methods
- download(source: string, dest: string, options?: Options):
Observable< DownloadResults > - downloads the contents
of
source
todest
if both exist. The next function returns the following object:
- upload(patterns: string | string[], dest: string,
options?: Options): Observable< UploadResults > - expands the source paths
using the glob module (
patterns
argument), uploads all found files and directories to the specifieddest
. The next function returns the following object:
Examples
In this example we connect to a server, and simultaneously upload all files from the test
directory, overwriting only
older files found on the server, and download files from /public_html/test
directory.
;;; ;; ; ftpClient.connect.pipe switchMapToftpClient.upload upath.join__dirname, 'test/*', './', , ,.subscribe console.inforesults, console.errorerr,console.info'Upload Complete',; ftpClient.connect.pipe switchMapToftpClient.download '/public_html/test', __dirname, ,.subscribe console.inforesults, console.errorerr,console.info'Download Complete',;
TODO
- Update this document with the different functions added