scp.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. const { Client } = require('node-scp')
  2. const dotenv = require("dotenv").config();
  3. const ssh = require("./ssh");
  4. // with ES Module
  5. function scp1(fileName)
  6. {
  7. Client({
  8. host: process.env.BOOLE,
  9. port: 22,
  10. username: process.env.SSH_USER,
  11. password: process.env.SSH_PASSWORD,
  12. tryKeyboard: true,
  13. }).then(client => {
  14. client.uploadFile("/Users/chrisdrakeford/Apitest/" + fileName, "/home/cdrakeford/apitest/" + fileName)
  15. .then(response => {
  16. console.log(fileName + " uploaded")
  17. client.close() // remember to close connection after you finish
  18. })
  19. .catch(error => {})
  20. }).catch(e => console.log(e))
  21. }
  22. function scp2(fileName)
  23. {
  24. Client({
  25. host: process.env.GROVE,
  26. port: 22,
  27. username: process.env.SSH_USER,
  28. password: process.env.SSH_PASSWORD,
  29. tryKeyboard: true,
  30. }).then(client => {
  31. client.uploadFile("/home/cdrakeford/apitest/" + fileName, "/home/cdrakeford/apitest/" + fileName)
  32. .then(response => {
  33. console.log(fileName + " uploaded")
  34. client.close() // remember to close connection after you finish
  35. })
  36. .catch(error => {})
  37. }).catch(e => console.log(e))
  38. }
  39. module.exports = {
  40. scp1,
  41. scp2,
  42. }