# whoosh

> A streaming sftp client

Latest version **2.0.2** (published 2022-08-16) · ISC license · 0 weekly downloads

## Install

```sh
npm install whoosh
pnpm add whoosh
yarn add whoosh
bun add whoosh
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.2 |
| Published | 2022-08-16 |
| First published | 2015-06-08 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=14 |
| Dependencies | 3 |
| Unpacked size | 23.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 15 |
| Author | GuideSmiths |
| Maintainers | cressie176, ulisesgascon, feliun, guidesmiths_bot |
| Keywords | sftp, streaming, client |

## Links

- npm: https://www.npmjs.com/package/whoosh
- Repository: https://github.com/guidesmiths/whoosh
- Homepage: https://guidesmiths.github.io/whoosh/
- Issues: https://github.com/guidesmiths/whoosh/issues
- npm.io page: https://npm.io/package/whoosh

## Dependencies (3)

- [ssh2](https://npm.io/package/ssh2.md) ^1.10.0
- [debug](https://npm.io/package/debug.md) ^4.3.4
- [lodash](https://npm.io/package/lodash.md) ^4.17.21

## Alternatives

- [launchdarkly-js-client-sdk](https://npm.io/package/launchdarkly-js-client-sdk.md) — 2.5M weekly downloads
- [@elastic/elasticsearch](https://npm.io/package/@elastic/elasticsearch.md) — 2.1M weekly downloads
- [@c8y/client](https://npm.io/package/@c8y/client.md) — 15.3K weekly downloads
- [@signaldb/maverickjs](https://npm.io/package/@signaldb/maverickjs.md) — 1.7K weekly downloads
- [@bbc/http-transport-cache](https://npm.io/package/@bbc/http-transport-cache.md) — 1.2K weekly downloads

## Recent versions

- 2.0.2 (latest) — 2022-08-16
- 2.0.1 — 2022-06-10
- 2.0.0 — 2022-06-10
- 1.4.0 — 2019-04-07
- 1.3.0 — 2018-10-07
- 1.2.0 — 2018-09-04
- 1.1.3 — 2018-05-16
- 1.1.2 — 2017-11-02
- 1.1.1 — 2017-03-30
- 1.1.0 — 2017-01-24
- 0.3.7 — 2016-02-04
- 0.3.6 — 2015-07-01
- 0.3.5 — 2015-07-01
- 0.3.4 — 2015-06-23
- 0.3.2 — 2015-06-23
- … 8 more at https://npm.io/package/whoosh/versions

## README

# Whoosh

Whoosh is an ultra thin wrapper for [SFTPStream](https://github.com/mscdex/ssh2-streams/blob/master/SFTPStream.md), with the additional benefit of being able to easily transfer in memory content to/from an SFTP server.

[![NPM version](https://img.shields.io/npm/v/whoosh.svg?style=flat-square)](https://www.npmjs.com/package/whoosh)
[![NPM downloads](https://img.shields.io/npm/dm/whoosh.svg?style=flat-square)](https://www.npmjs.com/package/whoosh)
[![Code Climate](https://codeclimate.com/github/guidesmiths/whoosh/badges/gpa.svg)](https://codeclimate.com/github/guidesmiths/whoosh)
[![Test Coverage](https://codeclimate.com/github/guidesmiths/whoosh/badges/coverage.svg)](https://codeclimate.com/github/guidesmiths/whoosh/coverage)
[![Code Style](https://img.shields.io/badge/code%20style-prettier-brightgreen.svg)](https://github.com/prettier/prettier)
[![Discover zUnit](https://img.shields.io/badge/Discover-zUnit-brightgreen)](https://www.npmjs.com/package/zunit)

## API

### connect(&lt;params&gt;, &lt;cb&gt;)

Connect to an sftp server

```js
Whoosh.connect(
  {
    hostname: 'sftp.example.com',
    port: 22,
    username: 'fred',
    password: 'secret',
  },
  (err, client) => {
    // profit :)
  }
);
```

See the [ssh2 client docs](https://github.com/mscdex/ssh2#client-methods) for a full list of connection parameters

### disconnect(&lt;cb&gt;)

Disconnect from an sftp server

```
Whoosh.connect(config, (err, client) => {
    client.disconnect(() => {
        // Disconnected
    })
})
```

### isConnected()

Returns true when connected to the SFTP server. Useful for checking whether a previously established connection has dropped.

```js
Whoosh.connect(config, (err, client) => {
  if (err) throw err;
  client.isConnected(); // returns true
});
```

### isConnected(&lt;cb&gt;)

Asynchronous version of isConnected

```js
Whoosh.connect(config, (err, client) => {
  if (err) throw err;
  client.isConnected((err, connected) => {
    // Check connected status here
  });
});
```

### getContent(&lt;path&gt;, [&lt;options&gt;], &lt;cb&gt;)

Downloads the contents of a remote file into a variable

```js
Whoosh.connect(config, (err, client) => {
  if (err) throw err;
  client.getContent('some/remote/file', (err, content, stats) => {
    client.disconnect(() => {
      if (err) throw err;
      console.log(`Downloaded ${stats.bytes} bytes in ${stats.duration} ms`);
    });
  });
});
```

The options parameter is is optional. When specified it is passed straight through to [SFTPStream's](https://github.com/mscdex/ssh2-streams/blob/master/SFTPStream.md) `createReadStream` method.

### putContent(&lt;content&gt;, &lt;path&gt;, [&lt;options&gt;], &lt;cb&gt;)

Uploads the contents of a variable to a remote file

```js
Whoosh.connect(config, (err, client) => {
  if (err) throw err;
  client.putContent('some conent', 'some/remote/file', (err, stats) => {
    client.disconnect(() => {
      if (err) throw err;
      console.log(`Uploaded ${stats.bytes} bytes in ${stats.duration} ms`);
    });
  });
});
```

The options parameter is is optional. When specified it is passed straight through to [SFTPStream's](https://github.com/mscdex/ssh2-streams/blob/master/SFTPStream.md) `createWriteStream` method.

### exists

Reports on whether a remote file exists

```js
Whoosh.connect(config, function (err, client) {
  if (err) throw err;
  client.exists('some/remote/file', (err, exists) => {
    client.disconnect(() => {
      if (err) throw err;
      console.log(exists ? 'File exists' : 'File does not exist');
    });
  });
});
```

## Everything else

The `client` object is just a decorated instance of [SFTPStream](https://github.com/mscdex/ssh2-streams/blob/master/SFTPStream.md) so all the other SFTP methods are available. e.g.

```js
Whoosh.connect(config, function (err, client) {
  if (err) throw err;
  client.unlink('some/remote/file', function (err) {
    client.disconnect(() => {
      if (err) throw err;
      console.log('Deleted some/remote/file');
    });
  });
});
```

### keyboard interactive

If the server requires keyboard interactive authentication you can configure this as follows...

```js
Whoosh.connect(
  {
    hostname: 'sftp.example.com',
    port: 22,
    tryKeyboard: true,
    challenges: [
      {
        pattern: /^Username:$/,
        response: 'fred',
      },
      {
        pattern: /^Password:$/,
        response: 'secret',
      },
    ],
  },
  (err, client) => {
    // profit :)
  }
);
```

The exact challenge patterns will be server dependent.

### Running tests

```
docker network create local
npm run docker
npm t
```

---
_Source: https://npm.io/package/whoosh · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
