Comparing version 9.0.0 to 10.0.0
@@ -0,1 +1,6 @@ | ||
#### 10.0.0 | ||
* Unixy all paths before passing onwards | ||
* Add `isConnected` method | ||
#### 9.0.0 | ||
@@ -2,0 +7,0 @@ |
@@ -25,2 +25,14 @@ "use strict"; | ||
}; | ||
class SSHError extends Error { | ||
constructor(message, code = null) { | ||
super(message); | ||
this.code = code; | ||
} | ||
} | ||
function unixifyPath(path) { | ||
if (path.includes('\\')) { | ||
return path.split('\\').join('/'); | ||
} | ||
return path; | ||
} | ||
async function readFile(filePath) { | ||
@@ -85,8 +97,2 @@ return new Promise((resolve, reject) => { | ||
} | ||
class SSHError extends Error { | ||
constructor(message, code = null) { | ||
super(message); | ||
this.code = code; | ||
} | ||
} | ||
class NodeSSH { | ||
@@ -178,2 +184,5 @@ constructor() { | ||
} | ||
isConnected() { | ||
return this.connection != null; | ||
} | ||
async requestShell() { | ||
@@ -311,7 +320,7 @@ const connection = this.getConnection(); | ||
if (method === 'exec') { | ||
await this.exec('mkdir', ['-p', path]); | ||
await this.exec('mkdir', ['-p', unixifyPath(path)]); | ||
return; | ||
} | ||
const sftp = givenSftp || (await this.requestSFTP()); | ||
const makeSftpDirectory = async (retry) => makeDirectoryWithSftp(path, sftp).catch(async (error) => { | ||
const makeSftpDirectory = async (retry) => makeDirectoryWithSftp(unixifyPath(path), sftp).catch(async (error) => { | ||
if (!retry || error == null || (error.message !== 'No such file' && error.code !== 'ENOENT')) { | ||
@@ -340,3 +349,3 @@ throw error; | ||
await new Promise((resolve, reject) => { | ||
sftp.fastGet(remoteFile, localFile, transferOptions || {}, err => { | ||
sftp.fastGet(remoteFile, unixifyPath(localFile), transferOptions || {}, err => { | ||
if (err) { | ||
@@ -370,3 +379,3 @@ reject(err); | ||
return new Promise(function (resolve, reject) { | ||
sftp.fastPut(localFile, remoteFile, transferOptions || {}, err => { | ||
sftp.fastPut(localFile, unixifyPath(remoteFile), transferOptions || {}, err => { | ||
if (err == null) { | ||
@@ -457,6 +466,3 @@ resolve(); | ||
.add(async () => { | ||
await this.mkdir(path_1.default | ||
.join(remoteDirectory, directory) | ||
.split(path_1.default.sep) | ||
.join('/'), 'sftp', sftp); | ||
await this.mkdir(path_1.default.join(remoteDirectory, directory), 'sftp', sftp); | ||
}) | ||
@@ -474,6 +480,3 @@ .catch(reject); | ||
const localFile = path_1.default.join(localDirectory, file); | ||
const remoteFile = path_1.default | ||
.join(remoteDirectory, file) | ||
.split(path_1.default.sep) | ||
.join('/'); | ||
const remoteFile = path_1.default.join(remoteDirectory, file); | ||
try { | ||
@@ -547,8 +550,2 @@ await this.putFile(localFile, remoteFile, sftp, transferOptions); | ||
let failed = false; | ||
const directoriesCreated = new Set(); | ||
const createDirectory = async (path) => { | ||
if (!directoriesCreated.has(path)) { | ||
directoriesCreated.add(path); | ||
} | ||
}; | ||
try { | ||
@@ -561,6 +558,3 @@ // Do the directories first. | ||
.add(async () => { | ||
await make_dir_1.default(path_1.default | ||
.join(localDirectory, directory) | ||
.split('/') | ||
.join(path_1.default.sep)); | ||
await make_dir_1.default(path_1.default.join(localDirectory, directory)); | ||
}) | ||
@@ -578,7 +572,3 @@ .catch(reject); | ||
const localFile = path_1.default.join(localDirectory, file); | ||
const remoteFile = path_1.default | ||
.join(remoteDirectory, file) | ||
.split(path_1.default.sep) | ||
.join('/'); | ||
await createDirectory(path_1.default.dirname(remoteFile)); | ||
const remoteFile = path_1.default.join(remoteDirectory, file); | ||
try { | ||
@@ -585,0 +575,0 @@ await this.getFile(localFile, remoteFile, sftp, transferOptions); |
@@ -43,2 +43,3 @@ /// <reference types="node" /> | ||
connect(givenConfig: Config): Promise<this>; | ||
isConnected(): boolean; | ||
requestShell(): Promise<ClientChannel>; | ||
@@ -45,0 +46,0 @@ withShell(callback: (channel: ClientChannel) => Promise<void>): Promise<void>; |
{ | ||
"name": "node-ssh", | ||
"version": "9.0.0", | ||
"version": "10.0.0", | ||
"description": "SS2 with Promises", | ||
@@ -5,0 +5,0 @@ "main": "lib/cjs/index.js", |
@@ -154,4 +154,7 @@ Node-SSH - SSH2 with Promises | ||
connection: Client | null; | ||
connect(config: Config): Promise<this>; | ||
isConnected(): boolean; | ||
requestShell(): Promise<ClientChannel>; | ||
@@ -158,0 +161,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
266
0
41531
657