npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

rx-node-ftp-client

v1.1.0

Published

A Reactive and Typescript FTP client based on the ftp-client package

Downloads

49

Readme

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:

import { Client } from 'rx-node-ftp-client';
ftpClient = new Client(config, 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 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:

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:

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:
{
  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:
{
  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.

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