chrisdrakeford c21337f41c async | 3 년 전 | |
---|---|---|
.. | ||
.husky | 3 년 전 | |
lib | 3 년 전 | |
CHANGELOG.md | 3 년 전 | |
LICENSE | 3 년 전 | |
README.md | 3 년 전 | |
commitlint.config.js | 3 년 전 | |
package.json | 3 년 전 |
A lightweight, fast and secure module to perform SCP commands for NodeJS based on SSH2
All functionalities are written using Promise. That means you can use it with Promise
or Async/Await
(No more callback hell, Yeah :) )
And other new features:
mkdir
, stat
, check if path existsnpm install --save node-scp
# or
yarn add node-scp
Using Promise
// with commonJS
const { Client } = require('node-scp')
// with ES Module
import { Client } from 'node-scp'
Client({
host: 'your host',
port: 22,
username: 'username',
password: 'password',
// privateKey: fs.readFileSync('./key.pem'),
// passphrase: 'your key passphrase',
}).then(client => {
client.uploadFile('./test.txt', '/workspace/test.txt')
.then(response => {
client.close() // remember to close connection after you finish
})
.catch(error => {})
}).catch(e => console.log(e))
Using async/await
:
// with commonJS
const { Client } = require('node-scp')
// with ES Module
import { Client } from 'node-scp'
async function test() {
try {
const client = await Client({
host: 'your host',
port: 22,
username: 'username',
password: 'password',
// privateKey: fs.readFileSync('./key.pem'),
// passphrase: 'your key passphrase',
})
await client.uploadFile('./test.txt', '/workspace/test.txt')
// you can perform upload multiple times
await client.uploadFile('./test1.txt', '/workspace/test1.txt')
client.close() // remember to close connection after you finish
} catch (e) {
console.log(e)
}
}
test()
Using Promise
// with commonJS
const { Client } = require('node-scp')
// with ES Module
import { Client } from 'node-scp'
Client({
host: 'your host',
port: 22,
username: 'username',
password: 'password',
// privateKey: fs.readFileSync('./key.pem'),
// passphrase: 'your key passphrase',
}).then(client => {
client.downloadFile('/workspace/test.txt', './test.txt')
.then(response => {
client.close() // remember to close connection after you finish
})
.catch(error => {})
}).catch(e => console.log(e))
Using async/await
:
// with commonJS
const { Client } = require('node-scp')
// with ES Module
import { Client } from 'node-scp'
async function test () {
try {
const client = await Client({
host: 'your host',
port: 22,
username: 'username',
password: 'password',
// privateKey: fs.readFileSync('./key.pem'),
// passphrase: 'your key passphrase',
})
await client.downloadFile('/workspace/test.txt', './test.txt')
client.close() // remember to close connection after you finish
} catch(e) {
console.log(e)
}
}
test()
Using Promise
// with commonJS
const { Client } = require('node-scp')
// with ES Module
import { Client } from 'node-scp'
Client({
host: 'your host',
port: 22,
username: 'username',
password: 'password',
// privateKey: fs.readFileSync('./key.pem'),
// passphrase: 'your key passphrase',
}).then(client => {
client.uploadDir('./local/dir', '/server/path')
.then(response => {
client.close() // remember to close connection after you finish
})
.catch(error => {})
}).catch(e => console.log(e))
Using async/await
:
// with commonJS
const { Client } = require('node-scp')
// with ES Module
import { Client } from 'node-scp'
async funtion test () {
try {
const client = await Client({
host: 'your host',
port: 22,
username: 'username',
password: 'password',
// privateKey: fs.readFileSync('./key.pem'),
// passphrase: 'your key passphrase',
})
await client.uploadDir('./local/dir', '/server/path')
client.close() // remember to close connection after you finish
} catch (e) {
console.log(e)
}
}
test()
Using Promise
// with commonJS
const { Client } = require('node-scp')
// with ES Module
import { Client } from 'node-scp'
Client({
host: 'your host',
port: 22,
username: 'username',
password: 'password',
// privateKey: fs.readFileSync('./key.pem'),
// passphrase: 'your key passphrase',
}).then(client => {
client.downloadDir('/server/path', 'local/path')
.then(response => {
client.close() // remember to close connection after you finish
})
.catch(error => {})
}).catch(e => console.log(e))
Using async/await
:
// with commonJS
const { Client } = require('node-scp')
// with ES Module
import { Client } from 'node-scp'
async funtion test () {
try {
const client = await Client({
host: 'your host',
port: 22,
username: 'username',
password: 'password',
// privateKey: fs.readFileSync('./key.pem'),
// passphrase: 'your key passphrase',
})
await client.downloadDir('./local/dir', '/server/path')
client.close() // remember to close connection after you finish
} catch (e) {
console.log(e)
}
}
test()
Using Promise
// with commonJS
const { Client } = require('node-scp')
// with ES Module
import { Client } from 'node-scp'
Client({
host: 'your host',
port: 22,
username: 'username',
password: 'password',
// privateKey: fs.readFileSync('./key.pem'),
// passphrase: 'your key passphrase',
}).then(client => {
client.mkdir('/server/path')
.then(response => {
client.close() // remember to close connection after you finish
})
.catch(error => {})
}).catch(e => console.log(e))
Using async/await
:
// with commonJS
const { Client } = require('node-scp')
// with ES Module
import { Client } from 'node-scp'
async function test() {
try {
const client = await Client({
host: 'your host',
port: 22,
username: 'username',
password: 'password',
// privateKey: fs.readFileSync('./key.pem'),
// passphrase: 'your key passphrase',
})
await client.mkdir('/server/path')
client.close() // remember to close connection after you finish
} catch (e) {
console.log(e)
}
}
test()
Using Promise
// with commonJS
const { Client } = require('node-scp')
// with ES Module
import { Client } from 'node-scp'
Client({
host: 'your host',
port: 22,
username: 'username',
password: 'password',
// privateKey: fs.readFileSync('./key.pem'),
// passphrase: 'your key passphrase',
}).then(client => {
const result = client.exists('/server/path')
.then(result => {
console.log(result)
client.close() // remember to close connection after you finish
})
.catch(error => {})
}).catch(e => console.log(e))
Using async/await
:
// with commonJS
const { Client } = require('node-scp')
// with ES Module
import { Client } from 'node-scp'
async function test() {
try {
const client = await Client({
host: 'your host',
port: 22,
username: 'username',
password: 'password',
// privateKey: fs.readFileSync('./key.pem'),
// passphrase: 'your key passphrase',
})
const result = await client.exists('/server/path')
console.log(result)
client.close() // remember to close connection after you finish
} catch (e) {
console.log(e)
}
}
test()
Using Promise
// with commonJS
const { Client } = require('node-scp')
// with ES Module
import { Client } from 'node-scp'
Client({
host: 'your host',
port: 22,
username: 'username',
password: 'password',
// privateKey: fs.readFileSync('./key.pem'),
// passphrase: 'your key passphrase',
}).then(client => {
client.stat('/server/path')
.then(result => {
console.log(result)
client.close() // remember to close connection after you finish
})
.catch(error => {})
}).catch(e => console.log(e))
Using async/await
:
// with commonJS
const { Client } = require('node-scp')
// with ES Module
import { Client } from 'node-scp'
async function test() {
try {
const client = await Client({
host: 'your host',
port: 22,
username: 'username',
password: 'password',
// privateKey: fs.readFileSync('./key.pem'),
// passphrase: 'your key passphrase',
})
cosnt result = await client.stat('/server/path')
console.log(result)
client.close() // remember to close connection after you finish
} catch (e) {
console.log(e)
}
}
test()
Using Promise
// with commonJS
const { Client } = require('node-scp')
// with ES Module
import { Client } from 'node-scp'
Client({
host: 'your host',
port: 22,
username: 'username',
password: 'password',
// privateKey: fs.readFileSync('./key.pem'),
// passphrase: 'your key passphrase',
}).then(client => {
client.list('/server/path')
.then(result => {
console.log(result)
client.close() // remember to close connection after you finish
})
.catch(error => {})
}).catch(e => console.log(e))
Using async/await
:
// with commonJS
const { Client } = require('node-scp')
// with ES Module
import { Client } from 'node-scp'
async function test() {
try {
const client = await Client({
host: 'your host',
port: 22,
username: 'username',
password: 'password',
// privateKey: fs.readFileSync('./key.pem'),
// passphrase: 'your key passphrase',
})
cosnt result = await client.list('/server/path')
console.log(result)
client.close() // remember to close connection after you finish
} catch (e) {
console.log(e)
}
}
test()
Using Promise
// with commonJS
const { Client } = require('node-scp')
// with ES Module
import { Client } from 'node-scp'
Client({
host: 'your host',
port: 22,
username: 'username',
password: 'password',
// privateKey: fs.readFileSync('./key.pem'),
// passphrase: 'your key passphrase',
}).then(client => {
client.realPath('/server/path')
.then(result => {
console.log(result)
client.close() // remember to close connection after you finish
})
.catch(error => {})
}).catch(e => console.log(e))
Using async/await
:
// with commonJS
const { Client } = require('node-scp')
// with ES Module
import { Client } from 'node-scp'
async function test() {
try {
const client = await Client({
host: 'your host',
port: 22,
username: 'username',
password: 'password',
// privateKey: fs.readFileSync('./key.pem'),
// passphrase: 'your key passphrase',
})
cosnt result = await client.realPath('/server/path')
console.log(result)
client.close() // remember to close connection after you finish
} catch (e) {
console.log(e)
}
}
test()
Below are available options you can pass when connecting to server:
localhost
22
host
. Default: false
host
. Default: false
Buffer
or string
that contains a private key for either key-based or hostbased user authentication (OpenSSH format). Default: (none)20000
0
3
posix
| win32
): use backslash \
for Windows or slash /
on posix system (Linux, MacOS) when handling remote server path. Default: posix
Default authentication method order: None -> Password -> Private Key
If you like this project, give me 1 ⭐️