1

I am using the this npm module for my SFTP iplementation.

As I need to create a folder on my SFTP server where I can upload my file. I have read the documentation but nothing is mentioned about this.

How to create a folder on SFTP server using ssh2 npm module?

James Z
  • 12,209
  • 10
  • 24
  • 44
Ankit Uniyal
  • 424
  • 1
  • 7
  • 20

1 Answers1

4

Try the below.

const Client = require("ssh2").Client; 
var connSettings = {
    host: "YourHostName",
    port: YourPortNumber,
    username: "YourUserName",
    password: "YourPassword"
};
var conn = new Client();
conn
  .on("ready", function() {
    conn.sftp(function(err, sftp) {
      if (err) throw err;
      sftp.mkdir(remoteFilePath, function(err) {
        if (err) {
          console.log("Failed to create directory!", err);
          conn.end();
        } else {
          console.log("Directory created on SFTP server");
          conn.end();
        }
      });
    });
  })
  .connect(connSettings);