https://github.com/roberto-naharro/rx-node-ftp-client
A Reactive and Typescript version of the module ftp-client
https://github.com/roberto-naharro/rx-node-ftp-client
client ftp observable reactive rx rxjs transfer
Last synced: 24 days ago
JSON representation
A Reactive and Typescript version of the module ftp-client
- Host: GitHub
- URL: https://github.com/roberto-naharro/rx-node-ftp-client
- Owner: roberto-naharro
- License: other
- Created: 2018-06-26T12:50:26.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2022-12-30T20:18:12.000Z (over 3 years ago)
- Last Synced: 2024-08-10T23:15:49.671Z (almost 2 years ago)
- Topics: client, ftp, observable, reactive, rx, rxjs, transfer
- Language: TypeScript
- Size: 792 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 10
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# rx-node-ftp-client
## Description
rx-node-ftp-client is an observable version of the package [ftp-client](https://github.com/noodny/node-ftp-client) - with some improvements.
## Requirements
* [node.js](http://nodejs.org/) -- v0.8.0 or newer
* npm -- v2.0.0 or newer
## Dependencies
* [rxjs](https://github.com/reactivex/rxjs) -- v6.2.1
* [ftp](https://github.com/mscdex/node-ftp) -- v0.3.10
* [glob](https://github.com/isaacs/node-glob) -- v7.1.2
* [lodash](https://github.com/lodash/lodash-node) -- v4.17.10
* [path](https://github.com/jinder/path) -- v4.17.10
* [upath](https://github.com/anodynos/upath) -- v1.1.10
## Installation
npm install rx-node-ftp-client
## Usage
### Initialization
To create an instance of the FTP client object:
TypeScript:
```typescript
import { Client } from 'rx-node-ftp-client';
ftpClient = new Client(config, options);
```
where `config` contains the ftp server configuration (these are the default values):
```javascript
{
host: 'localhost',
port: 21,
user: 'anonymous',
password: 'anonymous@'
}
```
(To check more options, see [the ftp npm package](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/ftp/index.d.ts#L18))
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 if `null`. 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:
```typescript
ftpClient.connect().subscribe(
() => console.log('Connected'),
err => console.error(err),
() => {
console.log('Operation finished'),
},
);
```
#### Disconnected
If you choose the option of manually disconnect from the server, you have to use the `disconnect` method:
```typescript
ftpClient.disconnect().subscribe(
() => console.log('Disconnected'),
err => console.error(err),
() => {
console.log('Operation finished'),
},
);
```
### Methods
* **download**(source: string, dest: string, options?: Options):
Observable< DownloadResults > - downloads the contents
of `source` to `dest` if both exist. The next function returns the following object:
```typescript
{
downloadedFiles: string[],
errors: {
[origin: string]: Error,
},
}
```
* **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 specified `dest`. The next function returns the following object:
```typescript
{
uploadedFiles: string[],
uploadedDirs: string[],
errors: {
[origin: string]: Error,
},
}
```
## 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.
```typescript
import { Client, Options, Config } from './lib/client';
import * as upath from 'upath';
import { switchMapTo } from 'rxjs/operators';
const config: Config = {
host: 'localhost',
port: 21,
user: 'anonymous',
password: 'anonymous@',
};
const options: Options = {
logging: 'basic',
};
const ftpClient = new Client(config, options);
ftpClient.connect().pipe(
switchMapTo(ftpClient.upload(
upath.join(__dirname, 'test/*'),
'./',
{ baseDir: __dirname },
)),
).subscribe(
results => console.info(results),
err => console.error(err),
() => console.info('Upload Complete'),
);
ftpClient.connect().pipe(
switchMapTo(ftpClient.download(
'/public_html/test',
__dirname,
)),
).subscribe(
results => console.info(results),
err => console.error(err),
() => console.info('Download Complete'),
);
```
## TODO
* Update this document with the different functions added