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
- Host: GitHub
- URL: https://github.com/wellwelwel/basic-sftp
- Owner: wellwelwel
- License: mit
- Created: 2023-01-10T10:51:38.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-04-08T00:18:59.000Z (about 2 years ago)
- Last Synced: 2025-02-08T21:48:29.095Z (3 months ago)
- Topics: sftp, sftp-client, sftp-download, sftp-promise, sftp-upload
- Language: TypeScript
- Homepage:
- Size: 49.8 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
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 | [](https://github.com/wellwelwel) |