An open API service indexing awesome lists of open source software.

https://github.com/wellwelwel/basic-sftp

๐Ÿคน๐Ÿปโ€โ™€๏ธ A basic promise-based SFTP Client
https://github.com/wellwelwel/basic-sftp

sftp sftp-client sftp-download sftp-promise sftp-upload

Last synced: about 2 months ago
JSON representation

๐Ÿคน๐Ÿปโ€โ™€๏ธ A basic promise-based SFTP Client

Awesome Lists containing this project

README

        

Basic SFTP


๐Ÿคน๐Ÿปโ€โ™€๏ธ A basic promise-based SFTP Client

## Install

```shell
npm i basic-sftp
```


### Usage

#### Import

- ES Modules

```javascript
import { Client } from 'basic-sftp';
```

- CommonJS

```javascript
const { Client } = require('basic-sftp');
```


#### Connect

```javascript
const sftp = new Client();

await sftp.connect({
host: '',
port: 22,
username: '',
password: '',
});
```

- The connection access extends all the [`ssh2`](https://github.com/mscdex/ssh2) options

#### Reconnect

```javascript
await sftp.reconnect();
```

#### Close Connection

```javascript
await sftp.end();
```


### Methods

#### ls

- Lists the contents of a directory

```javascript
await sftp.ls(path);
```

#### is

- Get the type from path: `File | Directory | null`

```javascript
await sftp.is(path);
```

- `File` means that the remote path is a **file**
- `Directory` means that the remote path is a **directory**
- `null` means that the remote path **doesn't exist**

#### ensureDir

- Creates the path recursively, if it does not exist

```javascript
await sftp.ensureDir(path);
```

#### uploadFile

- Uploads a local file to the remote server

```javascript
await sftp.uploadFile(localPath, remotePath);
```

#### downloadFile

- Downloads a remote file to the local workspace

```javascript
await sftp.downloadFile(remotePath, localPath);
```

#### unlink

- Remove all files and directories from a directory, including the directory itself, if it exists

```javascript
await sftp.unlink(path);
```

#### getConnection

- Brings up the original [`ssh2.sftp`](https://github.com/mscdex/ssh2/blob/master/SFTP.md) methods

```javascript
sftp.getConnection();
```


- [ ] Features
- [x] [`ls`](./src/functions/ls.ts)
- [x] [`is`](./src/functions/is.ts)
- [x] [`ensureDir`](./src/functions/ensureDir.ts)
- [x] [`unlink`](./src/functions/unlink.ts)
- [x] [`uploadFile`](./src/functions/uploadFile.ts)
- [x] [`downloadFile`](./src/functions/downloadFile.ts)
- [ ] `uploadDir`
- [ ] `downloadDir`


### Credits

| Contributions | GitHub |
| ------------- | ---------------------------------------------------------------------------------- |
| Author | [![wellwelwel](./.github/assets/readme/author.svg)](https://github.com/wellwelwel) |