@edirect/sftp-client 1.2.3 → 1.2.7
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/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/sftp-client.interface.d.ts +2 -1
- package/dist/sftp-client.module.js +8 -11
- package/dist/sftp-client.module.js.map +1 -1
- package/dist/sftp-client.service.d.ts +4 -0
- package/dist/sftp-client.service.js +85 -54
- package/dist/sftp-client.service.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -5845
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SftpClientService = exports.SftpClientModule = void 0;
|
|
3
4
|
var sftp_client_module_1 = require("./sftp-client.module");
|
|
4
5
|
Object.defineProperty(exports, "SftpClientModule", { enumerable: true, get: function () { return sftp_client_module_1.SftpClientModule; } });
|
|
5
6
|
var sftp_client_service_1 = require("./sftp-client.service");
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,2DAAwD;AAA/C,sHAAA,gBAAgB,OAAA;AACzB,6DAA0D;AAAjD,wHAAA,iBAAiB,OAAA"}
|
|
@@ -2,9 +2,10 @@
|
|
|
2
2
|
export interface ISFTPClientOptions {
|
|
3
3
|
host: string;
|
|
4
4
|
username: string;
|
|
5
|
-
password
|
|
5
|
+
password?: string;
|
|
6
6
|
port: string;
|
|
7
7
|
encoding?: string;
|
|
8
|
+
privateKey?: string | Buffer;
|
|
8
9
|
}
|
|
9
10
|
export interface ISftpClientInterface {
|
|
10
11
|
upload(options: ISFTPClientOptions, dataToUpload: string | Buffer, fileName: string): Promise<void>;
|
|
@@ -9,16 +9,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
9
9
|
exports.SftpClientModule = void 0;
|
|
10
10
|
const common_1 = require("@nestjs/common");
|
|
11
11
|
const sftp_client_service_1 = require("./sftp-client.service");
|
|
12
|
-
let SftpClientModule =
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
], SftpClientModule);
|
|
21
|
-
return SftpClientModule;
|
|
22
|
-
})();
|
|
12
|
+
let SftpClientModule = class SftpClientModule {
|
|
13
|
+
};
|
|
14
|
+
SftpClientModule = __decorate([
|
|
15
|
+
common_1.Module({
|
|
16
|
+
providers: [sftp_client_service_1.SftpClientService],
|
|
17
|
+
exports: [sftp_client_service_1.SftpClientService],
|
|
18
|
+
})
|
|
19
|
+
], SftpClientModule);
|
|
23
20
|
exports.SftpClientModule = SftpClientModule;
|
|
24
21
|
//# sourceMappingURL=sftp-client.module.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sftp-client.module.js","sourceRoot":"","sources":["../src/sftp-client.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAwC;AACxC,+DAA0D;AAM1D
|
|
1
|
+
{"version":3,"file":"sftp-client.module.js","sourceRoot":"","sources":["../src/sftp-client.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAwC;AACxC,+DAA0D;AAM1D,IAAa,gBAAgB,GAA7B,MAAa,gBAAgB;CAAG,CAAA;AAAnB,gBAAgB;IAJ5B,eAAM,CAAC;QACN,SAAS,EAAE,CAAC,uCAAiB,CAAC;QAC9B,OAAO,EAAE,CAAC,uCAAiB,CAAC;KAC7B,CAAC;GACW,gBAAgB,CAAG;AAAnB,4CAAgB"}
|
|
@@ -5,6 +5,10 @@ export declare class SftpClientService implements ISftpClientInterface {
|
|
|
5
5
|
constructor();
|
|
6
6
|
upload(options: ISFTPClientOptions, dataToUpload: string | Buffer, fileName: string): Promise<void>;
|
|
7
7
|
download(options: ISFTPClientOptions, fileName: string, downloadPath: string | Stream): Promise<void>;
|
|
8
|
+
posixRename(options: ISFTPClientOptions, fromPath: string, toPath: string): Promise<void>;
|
|
8
9
|
rename(options: ISFTPClientOptions, fromPath: string, toPath: string): Promise<void>;
|
|
10
|
+
listFiles(options: ISFTPClientOptions, path: string): Promise<string[]>;
|
|
11
|
+
getFileContent(options: ISFTPClientOptions, filePath: string): Promise<string>;
|
|
12
|
+
private connectToSftp;
|
|
9
13
|
private getSftpOptions;
|
|
10
14
|
}
|
|
@@ -12,63 +12,94 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.SftpClientService = void 0;
|
|
13
13
|
const common_1 = require("@nestjs/common");
|
|
14
14
|
const SFTPClient = require("ssh2-sftp-client");
|
|
15
|
-
let SftpClientService =
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
await SFTP.connect(config);
|
|
23
|
-
await SFTP.put(Buffer.from(dataToUpload), fileName);
|
|
24
|
-
await SFTP.end();
|
|
25
|
-
}
|
|
26
|
-
catch (error) {
|
|
27
|
-
throw new Error(`Error on save ${fileName} on SFTP Server: \n ${error}`);
|
|
28
|
-
}
|
|
15
|
+
let SftpClientService = class SftpClientService {
|
|
16
|
+
constructor() { }
|
|
17
|
+
async upload(options, dataToUpload, fileName) {
|
|
18
|
+
try {
|
|
19
|
+
const SFTP = await this.connectToSftp(options);
|
|
20
|
+
await SFTP.put(Buffer.from(dataToUpload), fileName);
|
|
21
|
+
await SFTP.end();
|
|
29
22
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
const config = this.getSftpOptions(options);
|
|
33
|
-
const SFTP = new SFTPClient();
|
|
34
|
-
await SFTP.connect(config);
|
|
35
|
-
await SFTP.get(fileName, downloadPath);
|
|
36
|
-
await SFTP.end();
|
|
37
|
-
}
|
|
38
|
-
catch (error) {
|
|
39
|
-
throw new Error(`Error on download ${fileName}: \n ${error}`);
|
|
40
|
-
}
|
|
23
|
+
catch (error) {
|
|
24
|
+
throw new Error(`Error on save ${fileName} on SFTP Server: \n ${error}`);
|
|
41
25
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
await SFTP.end();
|
|
49
|
-
}
|
|
50
|
-
catch (error) {
|
|
51
|
-
throw new Error(`Error on rename ${fromPath}: \n ${error}`);
|
|
52
|
-
}
|
|
26
|
+
}
|
|
27
|
+
async download(options, fileName, downloadPath) {
|
|
28
|
+
try {
|
|
29
|
+
const SFTP = await this.connectToSftp(options);
|
|
30
|
+
await SFTP.get(fileName, downloadPath);
|
|
31
|
+
await SFTP.end();
|
|
53
32
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
if (!host || !password || !port || !username) {
|
|
57
|
-
throw new Error('Options parameter is required.');
|
|
58
|
-
}
|
|
59
|
-
return {
|
|
60
|
-
host: options.host,
|
|
61
|
-
username: options.username,
|
|
62
|
-
password: options.password,
|
|
63
|
-
port: options.port,
|
|
64
|
-
};
|
|
33
|
+
catch (error) {
|
|
34
|
+
throw new Error(`Error on download ${fileName}: \n ${error}`);
|
|
65
35
|
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
}
|
|
36
|
+
}
|
|
37
|
+
async posixRename(options, fromPath, toPath) {
|
|
38
|
+
try {
|
|
39
|
+
const SFTP = await this.connectToSftp(options);
|
|
40
|
+
await SFTP.posixRename(fromPath, toPath);
|
|
41
|
+
await SFTP.end();
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
throw new Error(`Error on rename ${fromPath}: \n ${error}`);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
async rename(options, fromPath, toPath) {
|
|
48
|
+
try {
|
|
49
|
+
const SFTP = await this.connectToSftp(options);
|
|
50
|
+
await SFTP.rename(fromPath, toPath);
|
|
51
|
+
await SFTP.end();
|
|
52
|
+
}
|
|
53
|
+
catch (error) {
|
|
54
|
+
throw new Error(`Error on rename ${fromPath}: \n ${error}`);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
async listFiles(options, path) {
|
|
58
|
+
try {
|
|
59
|
+
const SFTP = await this.connectToSftp(options);
|
|
60
|
+
const list = await SFTP.list(path);
|
|
61
|
+
await SFTP.end();
|
|
62
|
+
return list.map((file) => file.name);
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
throw new Error(`Error on listing files ${path}: \n ${error}`);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
async getFileContent(options, filePath) {
|
|
69
|
+
try {
|
|
70
|
+
const SFTP = await this.connectToSftp(options);
|
|
71
|
+
const fileBuffer = await SFTP.get(filePath);
|
|
72
|
+
await SFTP.end();
|
|
73
|
+
return Buffer.from(fileBuffer).toString();
|
|
74
|
+
}
|
|
75
|
+
catch (error) {
|
|
76
|
+
throw new Error(`Error on getting file content ${filePath}: \n ${error}`);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
async connectToSftp(options) {
|
|
80
|
+
const sftpOptions = this.getSftpOptions(options);
|
|
81
|
+
const client = new SFTPClient();
|
|
82
|
+
await client.connect(sftpOptions);
|
|
83
|
+
return client;
|
|
84
|
+
}
|
|
85
|
+
getSftpOptions(options) {
|
|
86
|
+
const { host, password, port, username, encoding, privateKey } = options;
|
|
87
|
+
if (!host || (!password && !privateKey) || !port || !username) {
|
|
88
|
+
throw new Error('Options parameter is required.');
|
|
89
|
+
}
|
|
90
|
+
return {
|
|
91
|
+
host,
|
|
92
|
+
username,
|
|
93
|
+
password,
|
|
94
|
+
port,
|
|
95
|
+
encoding,
|
|
96
|
+
privateKey
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
SftpClientService = __decorate([
|
|
101
|
+
common_1.Injectable(),
|
|
102
|
+
__metadata("design:paramtypes", [])
|
|
103
|
+
], SftpClientService);
|
|
73
104
|
exports.SftpClientService = SftpClientService;
|
|
74
105
|
//# sourceMappingURL=sftp-client.service.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sftp-client.service.js","sourceRoot":"","sources":["../src/sftp-client.service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAA4C;AAC5C,+CAA+C;AAS/C
|
|
1
|
+
{"version":3,"file":"sftp-client.service.js","sourceRoot":"","sources":["../src/sftp-client.service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAA4C;AAC5C,+CAA+C;AAS/C,IAAa,iBAAiB,GAA9B,MAAa,iBAAiB;IAC5B,gBAAgB,CAAC;IAEV,KAAK,CAAC,MAAM,CACjB,OAA2B,EAC3B,YAA6B,EAC7B,QAAgB;QAEhB,IAAI;YACF,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;YAC/C,MAAM,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,EAAE,QAAQ,CAAC,CAAC;YACpD,MAAM,IAAI,CAAC,GAAG,EAAE,CAAC;SAClB;QAAC,OAAO,KAAK,EAAE;YACd,MAAM,IAAI,KAAK,CAAC,iBAAiB,QAAQ,uBAAuB,KAAK,EAAE,CAAC,CAAA;SACzE;IACH,CAAC;IAEM,KAAK,CAAC,QAAQ,CACnB,OAA2B,EAC3B,QAAgB,EAChB,YAA6B;QAE7B,IAAI;YACF,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;YAC/C,MAAM,IAAI,CAAC,GAAG,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAC;YACvC,MAAM,IAAI,CAAC,GAAG,EAAE,CAAC;SAClB;QAAC,OAAO,KAAK,EAAE;YACd,MAAM,IAAI,KAAK,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