[英]Create Folder on SFTP server using ssh2 npm module in NodeJS
I am using the this npm module for my SFTP iplementation. 我正在使用此 npm模块进行SFTP实施。
As I need to create a folder on my SFTP server where I can upload my file. 因为我需要在SFTP服务器上创建一个文件夹,可以在其中上传文件。 I have read the documentation but nothing is mentioned about this.
我已经阅读了文档,但是对此没有任何提及。
How to create a folder on SFTP server using ssh2 npm module? 如何使用ssh2 npm模块在SFTP服务器上创建文件夹?
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);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.