SHARE
TWEET

Node SSH Create Folder

nvictorme Nov 19th, 2019 167 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const SSHClient = require("ssh2-sftp-client");
  2. const fs = require("fs");
  3.  
  4. const sshOptions = {
  5.   host: process.env.SSH_HOST,
  6.   username: process.env.SSH_USERNAME,
  7.   password: process.env.SSH_PASSWORD,
  8.   passphrase: process.env.SSH_PASSPHRASE,
  9.   remoteDir: "/default/remote/folder/",
  10.   privateKey: fs.readFileSync(__dirname + "/path/to/key.pem")
  11. };
  12.  
  13. const sshClient = new SSHClient();
  14.  
  15. sshClient
  16.   .connect(sshOptions)
  17.   .then(() => {
  18.     return sshClient.mkdir("new_folder_path");
  19.   })
  20.   .then(folderCreated => {
  21.     return sshClient.end();
  22.   })
  23.   .then(() => {
  24.     process.exit(0);
  25.   })
  26.   .catch(error => {
  27.     console.error(error);
  28.   });
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top