@edirect/sftp-client 11.0.45 → 11.0.47
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/package.json +28 -0
- package/dist/src/index.d.ts +3 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +7 -0
- package/dist/src/sftp-client.interface.d.ts +19 -0
- package/dist/src/sftp-client.interface.d.ts.map +1 -0
- package/dist/src/sftp-client.interface.js +2 -0
- package/dist/src/sftp-client.module.d.ts +3 -0
- package/dist/src/sftp-client.module.d.ts.map +1 -0
- package/dist/src/sftp-client.module.js +15 -0
- package/dist/src/sftp-client.service.d.ts +13 -0
- package/dist/src/sftp-client.service.d.ts.map +1 -0
- package/dist/src/sftp-client.service.js +118 -0
- package/dist/tsconfig.lib.tsbuildinfo +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@edirect/sftp-client",
|
|
3
|
+
"version": "11.0.46",
|
|
4
|
+
"main": "./dist/src/index.js",
|
|
5
|
+
"types": "./dist/src/index.d.ts",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"import": "./dist/src/index.js",
|
|
9
|
+
"default": "./dist/src/index.js",
|
|
10
|
+
"require": "./dist/src/index.js",
|
|
11
|
+
"types": "./dist/src/index.d.ts"
|
|
12
|
+
},
|
|
13
|
+
"./package.json": "./package.json"
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"@nestjs/common": "^11.1.12",
|
|
20
|
+
"ssh2-sftp-client": "^12.0.1",
|
|
21
|
+
"tslib": "^2.8.1"
|
|
22
|
+
},
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"@types/node": "^25.0.10",
|
|
25
|
+
"@types/ssh2-sftp-client": "^9.0.6"
|
|
26
|
+
},
|
|
27
|
+
"type": "commonjs"
|
|
28
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SftpClientService = exports.SftpClientModule = void 0;
|
|
4
|
+
var sftp_client_module_1 = require("./sftp-client.module");
|
|
5
|
+
Object.defineProperty(exports, "SftpClientModule", { enumerable: true, get: function () { return sftp_client_module_1.SftpClientModule; } });
|
|
6
|
+
var sftp_client_service_1 = require("./sftp-client.service");
|
|
7
|
+
Object.defineProperty(exports, "SftpClientService", { enumerable: true, get: function () { return sftp_client_service_1.SftpClientService; } });
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export interface ISFTPClientOptions {
|
|
2
|
+
host: string;
|
|
3
|
+
username: string;
|
|
4
|
+
password?: string;
|
|
5
|
+
passphrase?: string;
|
|
6
|
+
port: string;
|
|
7
|
+
encoding?: string;
|
|
8
|
+
privateKey?: string | Buffer;
|
|
9
|
+
}
|
|
10
|
+
export interface ISftpClientInterface {
|
|
11
|
+
upload(options: ISFTPClientOptions, dataToUpload: string | Buffer, fileName: string): Promise<void>;
|
|
12
|
+
download(options: ISFTPClientOptions, fileName: string, downloadPath: string | NodeJS.WritableStream): Promise<void>;
|
|
13
|
+
delete(options: ISFTPClientOptions, deletePath: string): Promise<void>;
|
|
14
|
+
posixRename(options: ISFTPClientOptions, fromPath: string, toPath: string): Promise<void>;
|
|
15
|
+
rename(options: ISFTPClientOptions, fromPath: string, toPath: string): Promise<void>;
|
|
16
|
+
listFiles(options: ISFTPClientOptions, path: string, orderByModifiedDate?: 'ASC' | 'DESC'): Promise<string[]>;
|
|
17
|
+
getFileContent(options: ISFTPClientOptions, filePath: string): Promise<string>;
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=sftp-client.interface.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sftp-client.interface.d.ts","sourceRoot":"","sources":["../../src/sftp-client.interface.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;CAC9B;AAED,MAAM,WAAW,oBAAoB;IACnC,MAAM,CACJ,OAAO,EAAE,kBAAkB,EAC3B,YAAY,EAAE,MAAM,GAAG,MAAM,EAC7B,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,IAAI,CAAC,CAAC;IACjB,QAAQ,CACN,OAAO,EAAE,kBAAkB,EAC3B,QAAQ,EAAE,MAAM,EAChB,YAAY,EAAE,MAAM,GAAG,MAAM,CAAC,cAAc,GAC3C,OAAO,CAAC,IAAI,CAAC,CAAC;IACjB,MAAM,CAAC,OAAO,EAAE,kBAAkB,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACvE,WAAW,CACT,OAAO,EAAE,kBAAkB,EAC3B,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,IAAI,CAAC,CAAC;IACjB,MAAM,CACJ,OAAO,EAAE,kBAAkB,EAC3B,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,IAAI,CAAC,CAAC;IACjB,SAAS,CACP,OAAO,EAAE,kBAAkB,EAC3B,IAAI,EAAE,MAAM,EACZ,mBAAmB,CAAC,EAAE,KAAK,GAAG,MAAM,GACnC,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;IACrB,cAAc,CACZ,OAAO,EAAE,kBAAkB,EAC3B,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,MAAM,CAAC,CAAC;CACpB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sftp-client.module.d.ts","sourceRoot":"","sources":["../../src/sftp-client.module.ts"],"names":[],"mappings":"AAGA,qBAIa,gBAAgB;CAAG"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SftpClientModule = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const common_1 = require("@nestjs/common");
|
|
6
|
+
const sftp_client_service_1 = require("./sftp-client.service");
|
|
7
|
+
let SftpClientModule = class SftpClientModule {
|
|
8
|
+
};
|
|
9
|
+
exports.SftpClientModule = SftpClientModule;
|
|
10
|
+
exports.SftpClientModule = SftpClientModule = tslib_1.__decorate([
|
|
11
|
+
(0, common_1.Module)({
|
|
12
|
+
providers: [sftp_client_service_1.SftpClientService],
|
|
13
|
+
exports: [sftp_client_service_1.SftpClientService],
|
|
14
|
+
})
|
|
15
|
+
], SftpClientModule);
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ISftpClientInterface, ISFTPClientOptions } from './sftp-client.interface';
|
|
2
|
+
export declare class SftpClientService implements ISftpClientInterface {
|
|
3
|
+
upload(options: ISFTPClientOptions, dataToUpload: string | Buffer, fileName: string): Promise<void>;
|
|
4
|
+
download(options: ISFTPClientOptions, fileName: string, downloadPath: string | NodeJS.WritableStream): Promise<void>;
|
|
5
|
+
delete(options: ISFTPClientOptions, deletePath: string): Promise<void>;
|
|
6
|
+
posixRename(options: ISFTPClientOptions, fromPath: string, toPath: string): Promise<void>;
|
|
7
|
+
rename(options: ISFTPClientOptions, fromPath: string, toPath: string): Promise<void>;
|
|
8
|
+
listFiles(options: ISFTPClientOptions, path: string, orderByModifiedDate?: 'ASC' | 'DESC'): Promise<string[]>;
|
|
9
|
+
getFileContent(options: ISFTPClientOptions, filePath: string): Promise<string>;
|
|
10
|
+
private connectToSftp;
|
|
11
|
+
private getSftpOptions;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=sftp-client.service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sftp-client.service.d.ts","sourceRoot":"","sources":["../../src/sftp-client.service.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,oBAAoB,EACpB,kBAAkB,EACnB,MAAM,yBAAyB,CAAC;AAEjC,qBACa,iBAAkB,YAAW,oBAAoB;IAC/C,MAAM,CACjB,OAAO,EAAE,kBAAkB,EAC3B,YAAY,EAAE,MAAM,GAAG,MAAM,EAC7B,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,IAAI,CAAC;IAUH,QAAQ,CACnB,OAAO,EAAE,kBAAkB,EAC3B,QAAQ,EAAE,MAAM,EAChB,YAAY,EAAE,MAAM,GAAG,MAAM,CAAC,cAAc,GAC3C,OAAO,CAAC,IAAI,CAAC;IAUH,MAAM,CACjB,OAAO,EAAE,kBAAkB,EAC3B,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,IAAI,CAAC;IAUH,WAAW,CACtB,OAAO,EAAE,kBAAkB,EAC3B,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,IAAI,CAAC;IAUH,MAAM,CACjB,OAAO,EAAE,kBAAkB,EAC3B,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,IAAI,CAAC;IAUH,SAAS,CACpB,OAAO,EAAE,kBAAkB,EAC3B,IAAI,EAAE,MAAM,EACZ,mBAAmB,CAAC,EAAE,KAAK,GAAG,MAAM,GACnC,OAAO,CAAC,MAAM,EAAE,CAAC;IAqBP,cAAc,CACzB,OAAO,EAAE,kBAAkB,EAC3B,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,MAAM,CAAC;YAcJ,aAAa;IAO3B,OAAO,CAAC,cAAc;CAkBvB"}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SftpClientService = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const common_1 = require("@nestjs/common");
|
|
6
|
+
const ssh2_sftp_client_1 = tslib_1.__importDefault(require("ssh2-sftp-client"));
|
|
7
|
+
let SftpClientService = class SftpClientService {
|
|
8
|
+
async upload(options, dataToUpload, fileName) {
|
|
9
|
+
try {
|
|
10
|
+
const SFTP = await this.connectToSftp(options);
|
|
11
|
+
await SFTP.put(Buffer.from(dataToUpload), fileName);
|
|
12
|
+
await SFTP.end();
|
|
13
|
+
}
|
|
14
|
+
catch (error) {
|
|
15
|
+
throw new Error(`Error on save ${fileName} on SFTP Server: \n ${error}`);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
async download(options, fileName, downloadPath) {
|
|
19
|
+
try {
|
|
20
|
+
const SFTP = await this.connectToSftp(options);
|
|
21
|
+
await SFTP.get(fileName, downloadPath);
|
|
22
|
+
await SFTP.end();
|
|
23
|
+
}
|
|
24
|
+
catch (error) {
|
|
25
|
+
throw new Error(`Error on download ${fileName}: \n ${error}`);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
async delete(options, deletePath) {
|
|
29
|
+
try {
|
|
30
|
+
const SFTP = await this.connectToSftp(options);
|
|
31
|
+
await SFTP.delete(deletePath);
|
|
32
|
+
await SFTP.end();
|
|
33
|
+
}
|
|
34
|
+
catch (error) {
|
|
35
|
+
throw new Error(`Error on delete ${deletePath}: \n ${error}`);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
async posixRename(options, fromPath, toPath) {
|
|
39
|
+
try {
|
|
40
|
+
const SFTP = await this.connectToSftp(options);
|
|
41
|
+
await SFTP.posixRename(fromPath, toPath);
|
|
42
|
+
await SFTP.end();
|
|
43
|
+
}
|
|
44
|
+
catch (error) {
|
|
45
|
+
throw new Error(`Error on rename ${fromPath}: \n ${error}`);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
async rename(options, fromPath, toPath) {
|
|
49
|
+
try {
|
|
50
|
+
const SFTP = await this.connectToSftp(options);
|
|
51
|
+
await SFTP.rename(fromPath, toPath);
|
|
52
|
+
await SFTP.end();
|
|
53
|
+
}
|
|
54
|
+
catch (error) {
|
|
55
|
+
throw new Error(`Error on rename ${fromPath}: \n ${error}`);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
async listFiles(options, path, orderByModifiedDate) {
|
|
59
|
+
try {
|
|
60
|
+
const SFTP = await this.connectToSftp(options);
|
|
61
|
+
const list = await SFTP.list(path);
|
|
62
|
+
await SFTP.end();
|
|
63
|
+
return list
|
|
64
|
+
.sort((currentFile, nextFile) => {
|
|
65
|
+
if (orderByModifiedDate === 'ASC') {
|
|
66
|
+
return currentFile.modifyTime - nextFile.modifyTime;
|
|
67
|
+
}
|
|
68
|
+
if (orderByModifiedDate === 'DESC') {
|
|
69
|
+
return nextFile.modifyTime - currentFile.modifyTime;
|
|
70
|
+
}
|
|
71
|
+
return 0;
|
|
72
|
+
})
|
|
73
|
+
.map((file) => file.name);
|
|
74
|
+
}
|
|
75
|
+
catch (error) {
|
|
76
|
+
throw new Error(`Error on listing files ${path}: \n ${error}`);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
async getFileContent(options, filePath) {
|
|
80
|
+
try {
|
|
81
|
+
const SFTP = await this.connectToSftp(options);
|
|
82
|
+
const fileBuffer = await SFTP.get(filePath);
|
|
83
|
+
await SFTP.end();
|
|
84
|
+
if (Buffer.isBuffer(fileBuffer)) {
|
|
85
|
+
return fileBuffer.toString();
|
|
86
|
+
}
|
|
87
|
+
return fileBuffer;
|
|
88
|
+
}
|
|
89
|
+
catch (error) {
|
|
90
|
+
throw new Error(`Error on getting file content ${filePath}: \n ${error}`);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
async connectToSftp(options) {
|
|
94
|
+
const sftpOptions = this.getSftpOptions(options);
|
|
95
|
+
const client = new ssh2_sftp_client_1.default();
|
|
96
|
+
await client.connect(sftpOptions);
|
|
97
|
+
return client;
|
|
98
|
+
}
|
|
99
|
+
getSftpOptions(options) {
|
|
100
|
+
const { host, password, port, username, encoding, privateKey, passphrase } = options;
|
|
101
|
+
if (!host || (!password && !privateKey) || !port || !username) {
|
|
102
|
+
throw new Error('Options parameter is required.');
|
|
103
|
+
}
|
|
104
|
+
return {
|
|
105
|
+
host,
|
|
106
|
+
username,
|
|
107
|
+
password,
|
|
108
|
+
passphrase,
|
|
109
|
+
port: Number(port),
|
|
110
|
+
encoding,
|
|
111
|
+
privateKey,
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
exports.SftpClientService = SftpClientService;
|
|
116
|
+
exports.SftpClientService = SftpClientService = tslib_1.__decorate([
|
|
117
|
+
(0, common_1.Injectable)()
|
|
118
|
+
], SftpClientService);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":"5.9.3"}
|