@activepieces/piece-sftp 0.2.5 → 0.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.
Files changed (33) hide show
  1. package/package.json +13 -10
  2. package/src/index.d.ts +17 -1
  3. package/src/index.js +99 -23
  4. package/src/index.js.map +1 -1
  5. package/src/lib/actions/create-file.d.ts +2 -0
  6. package/src/lib/actions/create-file.js +39 -21
  7. package/src/lib/actions/create-file.js.map +1 -1
  8. package/src/lib/actions/create-folder.d.ts +2 -0
  9. package/src/lib/actions/create-folder.js +15 -13
  10. package/src/lib/actions/create-folder.js.map +1 -1
  11. package/src/lib/actions/delete-file.d.ts +2 -0
  12. package/src/lib/actions/delete-file.js +26 -14
  13. package/src/lib/actions/delete-file.js.map +1 -1
  14. package/src/lib/actions/delete-folder.d.ts +2 -0
  15. package/src/lib/actions/delete-folder.js +31 -14
  16. package/src/lib/actions/delete-folder.js.map +1 -1
  17. package/src/lib/actions/{list.d.ts → list-files.d.ts} +2 -0
  18. package/src/lib/actions/list-files.js +81 -0
  19. package/src/lib/actions/list-files.js.map +1 -0
  20. package/src/lib/actions/read-file.d.ts +2 -0
  21. package/src/lib/actions/read-file.js +52 -18
  22. package/src/lib/actions/read-file.js.map +1 -1
  23. package/src/lib/actions/rename-file-or-folder.d.ts +3 -0
  24. package/src/lib/actions/rename-file-or-folder.js +30 -12
  25. package/src/lib/actions/rename-file-or-folder.js.map +1 -1
  26. package/src/lib/actions/upload-file.d.ts +2 -0
  27. package/src/lib/actions/upload-file.js +35 -23
  28. package/src/lib/actions/upload-file.js.map +1 -1
  29. package/src/lib/triggers/new-modified-file.d.ts +6 -0
  30. package/src/lib/triggers/new-modified-file.js +33 -44
  31. package/src/lib/triggers/new-modified-file.js.map +1 -1
  32. package/src/lib/actions/list.js +0 -52
  33. package/src/lib/actions/list.js.map +0 -1
package/package.json CHANGED
@@ -1,25 +1,28 @@
1
1
  {
2
2
  "name": "@activepieces/piece-sftp",
3
- "version": "0.2.5",
3
+ "version": "0.2.7",
4
4
  "dependencies": {
5
- "@anthropic-ai/sdk": "0.27.3",
6
- "@sinclair/typebox": "0.33.18",
7
- "axios": "1.7.7",
5
+ "@anthropic-ai/sdk": "0.33.1",
6
+ "@sinclair/typebox": "0.34.11",
7
+ "axios": "1.8.2",
8
8
  "axios-retry": "4.4.1",
9
+ "basic-ftp": "5.0.5",
9
10
  "dayjs": "1.11.9",
10
- "deepmerge": "4.3.1",
11
+ "deepmerge-ts": "7.1.0",
11
12
  "mime-types": "2.1.35",
12
- "nanoid": "3.3.6",
13
+ "nanoid": "3.3.8",
13
14
  "openai": "4.67.1",
14
15
  "replicate": "0.34.1",
15
16
  "semver": "7.6.0",
16
17
  "ssh2-sftp-client": "9.1.0",
17
- "@activepieces/pieces-common": "0.2.28",
18
- "@activepieces/pieces-framework": "0.7.39",
19
- "@activepieces/shared": "0.10.126",
20
- "tslib": "2.6.2"
18
+ "zod": "3.23.8",
19
+ "@activepieces/pieces-common": "0.4.3",
20
+ "@activepieces/pieces-framework": "0.7.46",
21
+ "@activepieces/shared": "0.10.158",
22
+ "tslib": "1.14.1"
21
23
  },
22
24
  "overrides": {
25
+ "cross-spawn": "7.0.6",
23
26
  "@tryfabric/martian": {
24
27
  "@notionhq/client": "$@notionhq/client"
25
28
  },
package/src/index.d.ts CHANGED
@@ -1,10 +1,26 @@
1
+ import Client from 'ssh2-sftp-client';
2
+ import { Client as FTPClient } from 'basic-ftp';
3
+ export declare function getProtocolBackwardCompatibility(protocol: string | undefined): Promise<string>;
4
+ export declare function getClient<T extends Client | FTPClient>(auth: {
5
+ protocol: string | undefined;
6
+ host: string;
7
+ port: number;
8
+ allow_unauthorized_certificates: boolean | undefined;
9
+ username: string;
10
+ password: string;
11
+ }): Promise<T>;
12
+ export declare function endClient(client: Client | FTPClient, protocol: string | undefined): Promise<void>;
1
13
  export declare const sftpAuth: import("@activepieces/pieces-framework").CustomAuthProperty<{
14
+ protocol: import("@activepieces/pieces-framework").StaticDropdownProperty<string, false>;
15
+ allow_unauthorized_certificates: import("@activepieces/pieces-framework").CheckboxProperty<false>;
2
16
  host: import("@activepieces/pieces-framework").ShortTextProperty<true>;
3
17
  port: import("@activepieces/pieces-framework").NumberProperty<true>;
4
18
  username: import("@activepieces/pieces-framework").ShortTextProperty<true>;
5
19
  password: import("@activepieces/pieces-framework").SecretTextProperty<true>;
6
20
  }>;
7
- export declare const sftp: import("@activepieces/pieces-framework").Piece<import("@activepieces/pieces-framework").CustomAuthProperty<{
21
+ export declare const ftpSftp: import("@activepieces/pieces-framework").Piece<import("@activepieces/pieces-framework").CustomAuthProperty<{
22
+ protocol: import("@activepieces/pieces-framework").StaticDropdownProperty<string, false>;
23
+ allow_unauthorized_certificates: import("@activepieces/pieces-framework").CheckboxProperty<false>;
8
24
  host: import("@activepieces/pieces-framework").ShortTextProperty<true>;
9
25
  port: import("@activepieces/pieces-framework").NumberProperty<true>;
10
26
  username: import("@activepieces/pieces-framework").ShortTextProperty<true>;
package/src/index.js CHANGED
@@ -1,55 +1,129 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.sftp = exports.sftpAuth = void 0;
3
+ exports.ftpSftp = exports.sftpAuth = void 0;
4
+ exports.getProtocolBackwardCompatibility = getProtocolBackwardCompatibility;
5
+ exports.getClient = getClient;
6
+ exports.endClient = endClient;
4
7
  const tslib_1 = require("tslib");
5
8
  const pieces_framework_1 = require("@activepieces/pieces-framework");
6
9
  const shared_1 = require("@activepieces/shared");
7
10
  const ssh2_sftp_client_1 = tslib_1.__importDefault(require("ssh2-sftp-client"));
11
+ const basic_ftp_1 = require("basic-ftp");
8
12
  const create_file_1 = require("./lib/actions/create-file");
9
13
  const upload_file_1 = require("./lib/actions/upload-file");
10
14
  const read_file_1 = require("./lib/actions/read-file");
11
15
  const new_modified_file_1 = require("./lib/triggers/new-modified-file");
12
16
  const delete_folder_1 = require("./lib/actions/delete-folder");
13
17
  const delete_file_1 = require("./lib/actions/delete-file");
14
- const list_1 = require("./lib/actions/list");
18
+ const list_files_1 = require("./lib/actions/list-files");
15
19
  const create_folder_1 = require("./lib/actions/create-folder");
16
20
  const rename_file_or_folder_1 = require("./lib/actions/rename-file-or-folder");
21
+ function getProtocolBackwardCompatibility(protocol) {
22
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
23
+ if ((0, shared_1.isNil)(protocol)) {
24
+ return 'sftp';
25
+ }
26
+ return protocol;
27
+ });
28
+ }
29
+ function getClient(auth) {
30
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
31
+ const { protocol, host, port, allow_unauthorized_certificates, username, password } = auth;
32
+ const protocolBackwardCompatibility = yield getProtocolBackwardCompatibility(protocol);
33
+ if (protocolBackwardCompatibility === 'sftp') {
34
+ const sftp = new ssh2_sftp_client_1.default();
35
+ yield sftp.connect({
36
+ host,
37
+ port,
38
+ username,
39
+ password,
40
+ timeout: 10000,
41
+ });
42
+ return sftp;
43
+ }
44
+ else {
45
+ const ftpClient = new basic_ftp_1.Client();
46
+ yield ftpClient.access({
47
+ host,
48
+ port,
49
+ user: username,
50
+ password,
51
+ secure: protocolBackwardCompatibility === 'ftps',
52
+ secureOptions: {
53
+ rejectUnauthorized: !(allow_unauthorized_certificates !== null && allow_unauthorized_certificates !== void 0 ? allow_unauthorized_certificates : false),
54
+ }
55
+ });
56
+ return ftpClient;
57
+ }
58
+ });
59
+ }
60
+ function endClient(client, protocol) {
61
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
62
+ const protocolBackwardCompatibility = yield getProtocolBackwardCompatibility(protocol);
63
+ if (protocolBackwardCompatibility === 'sftp') {
64
+ yield client.end();
65
+ }
66
+ else {
67
+ client.close();
68
+ }
69
+ });
70
+ }
17
71
  exports.sftpAuth = pieces_framework_1.PieceAuth.CustomAuth({
18
- description: 'Enter the authentication details',
19
72
  props: {
73
+ protocol: pieces_framework_1.Property.StaticDropdown({
74
+ displayName: 'Protocol',
75
+ description: 'The protocol to use',
76
+ required: false,
77
+ options: {
78
+ options: [
79
+ { value: 'sftp', label: 'SFTP' },
80
+ { value: 'ftp', label: 'FTP' },
81
+ { value: 'ftps', label: 'FTPS' }
82
+ ],
83
+ },
84
+ }),
85
+ allow_unauthorized_certificates: pieces_framework_1.Property.Checkbox({
86
+ displayName: 'Allow Unauthorized Certificates',
87
+ description: 'Allow connections to servers with self-signed certificates',
88
+ defaultValue: false,
89
+ required: false,
90
+ }),
20
91
  host: pieces_framework_1.Property.ShortText({
21
92
  displayName: 'Host',
22
- description: 'The host of the SFTP server',
93
+ description: 'The host of the server',
23
94
  required: true,
24
95
  }),
25
96
  port: pieces_framework_1.Property.Number({
26
97
  displayName: 'Port',
27
- description: 'The port of the SFTP server',
98
+ description: 'The port of the server',
28
99
  required: true,
29
100
  defaultValue: 22,
30
101
  }),
31
102
  username: pieces_framework_1.Property.ShortText({
32
103
  displayName: 'Username',
33
- description: 'The username of the SFTP server',
104
+ description: 'The username to authenticate with',
34
105
  required: true,
35
106
  }),
36
107
  password: pieces_framework_1.PieceAuth.SecretText({
37
108
  displayName: 'Password',
38
- description: 'The password of the SFTP server',
109
+ description: 'The password to authenticate with',
39
110
  required: true,
40
111
  }),
41
112
  },
42
113
  validate: (_a) => tslib_1.__awaiter(void 0, [_a], void 0, function* ({ auth }) {
43
- const { host, port, username, password } = auth;
44
- const sftp = new ssh2_sftp_client_1.default();
114
+ let client = null;
115
+ const protocolBackwardCompatibility = yield getProtocolBackwardCompatibility(auth.protocol);
45
116
  try {
46
- yield sftp.connect({
47
- host,
48
- port,
49
- username,
50
- password,
51
- timeout: 10000,
52
- });
117
+ switch (protocolBackwardCompatibility) {
118
+ case 'sftp': {
119
+ client = yield getClient(auth);
120
+ break;
121
+ }
122
+ default: {
123
+ client = yield getClient(auth);
124
+ break;
125
+ }
126
+ }
53
127
  return {
54
128
  valid: true,
55
129
  };
@@ -57,19 +131,21 @@ exports.sftpAuth = pieces_framework_1.PieceAuth.CustomAuth({
57
131
  catch (err) {
58
132
  return {
59
133
  valid: false,
60
- error: 'Connection failed. Please check your credentials and try again.',
134
+ error: err === null || err === void 0 ? void 0 : err.message,
61
135
  };
62
136
  }
63
137
  finally {
64
- yield sftp.end();
138
+ if (client) {
139
+ yield endClient(client, auth.protocol);
140
+ }
65
141
  }
66
142
  }),
67
143
  required: true,
68
144
  });
69
- exports.sftp = (0, pieces_framework_1.createPiece)({
70
- displayName: 'SFTP',
71
- description: 'Secure file transfer protocol',
72
- minimumSupportedRelease: '0.7.1',
145
+ exports.ftpSftp = (0, pieces_framework_1.createPiece)({
146
+ displayName: 'FTP/SFTP',
147
+ description: 'Connect to FTP, FTPS or SFTP servers',
148
+ minimumSupportedRelease: '0.30.0',
73
149
  logoUrl: 'https://cdn.activepieces.com/pieces/sftp.svg',
74
150
  categories: [shared_1.PieceCategory.CORE, shared_1.PieceCategory.DEVELOPER_TOOLS],
75
151
  authors: [
@@ -87,7 +163,7 @@ exports.sftp = (0, pieces_framework_1.createPiece)({
87
163
  delete_file_1.deleteFileAction,
88
164
  create_folder_1.createFolderAction,
89
165
  delete_folder_1.deleteFolderAction,
90
- list_1.listFolderContentsAction,
166
+ list_files_1.listFolderContentsAction,
91
167
  rename_file_or_folder_1.renameFileOrFolderAction,
92
168
  ],
93
169
  triggers: [new_modified_file_1.newOrModifiedFile],
package/src/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../packages/pieces/community/sftp/src/index.ts"],"names":[],"mappings":";;;;AAAA,qEAIwC;AACxC,iDAAqD;AACrD,gFAAsC;AACtC,2DAAuD;AACvD,2DAA6D;AAC7D,uDAA0D;AAC1D,wEAAqE;AACrE,+DAAiE;AACjE,2DAA6D;AAC7D,6CAA8D;AAC9D,+DAAiE;AACjE,+EAA+E;AAClE,QAAA,QAAQ,GAAG,4BAAS,CAAC,UAAU,CAAC;IAC3C,WAAW,EAAE,kCAAkC;IAC/C,KAAK,EAAE;QACL,IAAI,EAAE,2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AAW,EAAE,MAAM;IACnB,WAAW,EAAE,+BAA+B;IAE5C,uBAAuB,EAAE,OAAO;IAChC,OAAO,EAAE,8CAA8C;IACvD,UAAU,EAAE,CAAC,sBAAa,CAAC,IAAI,EAAE,sBAAa,CAAC,eAAe,CAAC;IAC/D,OAAO,EAAE;QACP,qBAAqB;QACrB,YAAY;QACZ,sBAAsB;QACtB,eAAe;QACf,UAAU;KACX;IACD,IAAI,EAAE,gBAAQ;IACd,OAAO,EAAE;QACP,wBAAU;QACV,8BAAgB;QAChB,2BAAe;QACf,8BAAgB;QAChB,kCAAkB;QAClB,kCAAkB;QAClB,+BAAwB;QACxB,gDAAwB;KACzB;IACD,QAAQ,EAAE,CAAC,qCAAiB,CAAC;CAC9B,CAAC,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../packages/pieces/community/sftp/src/index.ts"],"names":[],"mappings":";;;AAkBA,4EAKC;AACD,8BA2BC;AAED,8BAOC;;AA5DD,qEAIwC;AACxC,iDAA4D;AAC5D,gFAAsC;AACtC,yCAAgD;AAChD,2DAAuD;AACvD,2DAA6D;AAC7D,uDAA0D;AAC1D,wEAAqE;AACrE,+DAAiE;AACjE,2DAA6D;AAC7D,yDAAoE;AACpE,+DAAiE;AACjE,+EAA+E;AAE/E,SAAsB,gCAAgC,CAAC,QAA4B;;QACjF,IAAI,IAAA,cAAK,EAAC,QAAQ,CAAC,EAAE,CAAC;YACpB,OAAO,MAAM,CAAC;QAChB,CAAC;QACD,OAAO,QAAQ,CAAC;IAClB,CAAC;CAAA;AACD,SAAsB,SAAS,CAA+B,IAA4J;;QACxN,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,+BAA+B,EAAE,QAAQ,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAC;QAC3F,MAAM,6BAA6B,GAAG,MAAM,gCAAgC,CAAC,QAAQ,CAAC,CAAC;QACvF,IAAI,6BAA6B,KAAK,MAAM,EAAE,CAAC;YAC7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oBAC1C,MAAM;gBACR,CAAC;YACH,CAAC;YACD,OAAO;gBACL,KAAK,EAAE,IAAI;aACZ,CAAC;QACJ,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,OAAO;gBACL,KAAK,EAAE,KAAK;gBACZ,KAAK,EAAG,GAAa,aAAb,GAAG,uBAAH,GAAG,CAAY,OAAO;aAC/B,CAAC;QACJ,CAAC;gBAAS,CAAC;YACT,IAAI,MAAM,EAAE,CAAC;gBACX,MAAM,SAAS,CAAC,MAAM,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;YACzC,CAAC;QACH,CAAC;IACH,CAAC,CAAA;IACD,QAAQ,EAAE,IAAI;CACf,CAAC,CAAC;AAEU,QAAA,OAAO,GAAG,IAAA,8BAAW,EAAC;IACjC,WAAW,EAAE,UAAU;IACvB,WAAW,EAAE,sCAAsC;IACnD,uBAAuB,EAAE,QAAQ;IACjC,OAAO,EAAE,8CAA8C;IACvD,UAAU,EAAE,CAAC,sBAAa,CAAC,IAAI,EAAE,sBAAa,CAAC,eAAe,CAAC;IAC/D,OAAO,EAAE;QACP,qBAAqB;QACrB,YAAY;QACZ,sBAAsB;QACtB,eAAe;QACf,UAAU;KACX;IACD,IAAI,EAAE,gBAAQ;IACd,OAAO,EAAE;QACP,wBAAU;QACV,8BAAgB;QAChB,2BAAe;QACf,8BAAgB;QAChB,kCAAkB;QAClB,kCAAkB;QAClB,qCAAwB;QACxB,gDAAwB;KACzB;IACD,QAAQ,EAAE,CAAC,qCAAiB,CAAC;CAC9B,CAAC,CAAC"}
@@ -1,4 +1,6 @@
1
1
  export declare const createFile: import("@activepieces/pieces-framework").IAction<import("@activepieces/pieces-framework").CustomAuthProperty<{
2
+ protocol: import("@activepieces/pieces-framework").StaticDropdownProperty<string, false>;
3
+ allow_unauthorized_certificates: import("@activepieces/pieces-framework").CheckboxProperty<false>;
2
4
  host: import("@activepieces/pieces-framework").ShortTextProperty<true>;
3
5
  port: import("@activepieces/pieces-framework").NumberProperty<true>;
4
6
  username: import("@activepieces/pieces-framework").ShortTextProperty<true>;
@@ -3,8 +3,31 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createFile = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const pieces_framework_1 = require("@activepieces/pieces-framework");
6
- const ssh2_sftp_client_1 = tslib_1.__importDefault(require("ssh2-sftp-client"));
7
6
  const __1 = require("../..");
7
+ const stream_1 = require("stream");
8
+ function createFileWithSFTP(client, fileName, fileContent) {
9
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
10
+ const remotePathExists = yield client.exists(fileName);
11
+ if (!remotePathExists) {
12
+ // Extract the directory path from the fileName
13
+ const remoteDirectory = fileName.substring(0, fileName.lastIndexOf('/'));
14
+ // Create the directory if it doesn't exist
15
+ yield client.mkdir(remoteDirectory, true);
16
+ }
17
+ yield client.put(Buffer.from(fileContent), fileName);
18
+ });
19
+ }
20
+ function createFileWithFTP(client, fileName, fileContent) {
21
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
22
+ // Extract the directory path from the fileName
23
+ const remoteDirectory = fileName.substring(0, fileName.lastIndexOf('/'));
24
+ // Create the directory if it doesn't exist
25
+ yield client.ensureDir(remoteDirectory);
26
+ // Upload the file content
27
+ const buffer = Buffer.from(fileContent);
28
+ yield client.uploadFrom(stream_1.Readable.from(buffer), fileName);
29
+ });
30
+ }
8
31
  exports.createFile = (0, pieces_framework_1.createAction)({
9
32
  auth: __1.sftpAuth,
10
33
  name: 'create_file',
@@ -22,40 +45,35 @@ exports.createFile = (0, pieces_framework_1.createAction)({
22
45
  },
23
46
  run(context) {
24
47
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
25
- const host = context.auth.host;
26
- const port = context.auth.port;
27
- const username = context.auth.username;
28
- const password = context.auth.password;
29
48
  const fileName = context.propsValue['fileName'];
30
49
  const fileContent = context.propsValue['fileContent'];
31
- const sftp = new ssh2_sftp_client_1.default();
50
+ const protocolBackwardCompatibility = yield (0, __1.getProtocolBackwardCompatibility)(context.auth.protocol);
51
+ const client = yield (0, __1.getClient)(context.auth);
32
52
  try {
33
- yield sftp.connect({
34
- host,
35
- port,
36
- username,
37
- password,
38
- });
39
- const remotePathExists = yield sftp.exists(fileName);
40
- if (!remotePathExists) {
41
- // Extract the directory path from the fileName
42
- const remoteDirectory = fileName.substring(0, fileName.lastIndexOf('/'));
43
- // Create the directory if it doesn't exist
44
- yield sftp.mkdir(remoteDirectory, true); // The second argument 'true' makes the function create all intermediate directories
45
- // You can also check if the directory was successfully created and handle any potential errors here
53
+ switch (protocolBackwardCompatibility) {
54
+ case 'ftps':
55
+ case 'ftp':
56
+ yield createFileWithFTP(client, fileName, fileContent);
57
+ break;
58
+ default:
59
+ case 'sftp':
60
+ yield createFileWithSFTP(client, fileName, fileContent);
61
+ break;
46
62
  }
47
- yield sftp.put(Buffer.from(fileContent), fileName);
48
- yield sftp.end();
49
63
  return {
50
64
  status: 'success',
51
65
  };
52
66
  }
53
67
  catch (err) {
68
+ console.error(err);
54
69
  return {
55
70
  status: 'error',
56
71
  error: err,
57
72
  };
58
73
  }
74
+ finally {
75
+ yield (0, __1.endClient)(client, context.auth.protocol);
76
+ }
59
77
  });
60
78
  },
61
79
  });
@@ -1 +1 @@
1
- {"version":3,"file":"create-file.js","sourceRoot":"","sources":["../../../../../../../../packages/pieces/community/sftp/src/lib/actions/create-file.ts"],"names":[],"mappings":";;;;AAAA,qEAAwE;AACxE,gFAAsC;AACtC,6BAAiC;AAEpB,QAAA,UAAU,GAAG,IAAA,+BAAY,EAAC;IACrC,IAAI,EAAE,YAAQ;IACd,IAAI,EAAE,aAAa;IACnB,WAAW,EAAE,uBAAuB;IACpC,WAAW,EAAE,qCAAqC;IAClD,KAAK,EAAE;QACL,QAAQ,EAAE,2BAAQ,CAAC,SAAS,CAAC;YAC3B,WAAW,EAAE,WAAW;YACxB,QAAQ,EAAE,IAAI;SACf,CAAC;QACF,WAAW,EAAE,2BAAQ,CAAC,QAAQ,CAAC;YA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AAO,GAAG,EAAE,CAAC;gBACb,OAAO;oBACL,MAAM,EAAE,OAAO;oBACf,KAAK,EAAE,GAAG;iBACX,CAAC;YACJ,CAAC;QACH,CAAC;KAAA;CACF,CAAC,CAAC"}
1
+ {"version":3,"file":"create-file.js","sourceRoot":"","sources":["../../../../../../../../packages/pieces/community/sftp/src/lib/actions/create-file.ts"],"names":[],"mappings":";;;;AAAA,qEAAwE;AAGxE,6BAAyF;AACzF,mCAAkC;AAElC,SAAe,kBAAkB,CAAC,MAAc,EAAE,QAAgB,EAAE,WAAmB;;QACnF,MAAM,gBAAgB,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;QACvD,IAAI,CAAC,gBAAgB,EAAE,CAAC;YACpB,+CAA+C;YAC/C,MAAM,eAAe,GAAG,QAAQ,CAAC,SAAS,CAAC,CAAC,EAAE,QAAQ,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC;YACzE,2CAA2C;YAC3C,MAAM,MAAM,CAAC,KAAK,CAAC,eAAe,EAAE,IAAI,CAAC,CAAC;QAC9C,CAAC;QACD,MAAM,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,EAAE,QAAQ,CAAC,CAAC;IACzD,CAAC;CAAA;AAED,SAAe,iBAAiB,CAAC,MAAiB,EAAE,QAAgB,EAAE,WAAmB;;QACrF,+CAA+C;QAC/C,MAAM,eAAe,GAAG,QAAQ,CAAC,SAAS,CAAC,CAAC,EAAE,QAAQ,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC;QACzE,2CAA2C;QAC3C,MAAM,MAAM,CAAC,SAAS,CAAC,eAAe,CAAC,CAAC;QACxC,0BAA0B;QAC1B,MAAM,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;QACxC,MAAM,MAAM,CAAC,UAAU,CAAC,iBAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,QAAQ,CAAC,C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,EAAE,GAAG;iBACb,CAAC;YACN,CAAC;oBAAS,CAAC;gBACP,MAAM,IAAA,aAAS,EAAC,MAAM,EAAE,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YACnD,CAAC;QACL,CAAC;KAAA;CACJ,CAAC,CAAC"}
@@ -1,4 +1,6 @@
1
1
  export declare const createFolderAction: import("@activepieces/pieces-framework").IAction<import("@activepieces/pieces-framework").CustomAuthProperty<{
2
+ protocol: import("@activepieces/pieces-framework").StaticDropdownProperty<string, false>;
3
+ allow_unauthorized_certificates: import("@activepieces/pieces-framework").CheckboxProperty<false>;
2
4
  host: import("@activepieces/pieces-framework").ShortTextProperty<true>;
3
5
  port: import("@activepieces/pieces-framework").NumberProperty<true>;
4
6
  username: import("@activepieces/pieces-framework").ShortTextProperty<true>;
@@ -4,7 +4,6 @@ exports.createFolderAction = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const index_1 = require("../../index");
6
6
  const pieces_framework_1 = require("@activepieces/pieces-framework");
7
- const ssh2_sftp_client_1 = tslib_1.__importDefault(require("ssh2-sftp-client"));
8
7
  exports.createFolderAction = (0, pieces_framework_1.createAction)({
9
8
  auth: index_1.sftpAuth,
10
9
  name: 'createFolder',
@@ -14,30 +13,33 @@ exports.createFolderAction = (0, pieces_framework_1.createAction)({
14
13
  folderPath: pieces_framework_1.Property.ShortText({
15
14
  displayName: 'Folder Path',
16
15
  required: true,
17
- description: 'The new folder path e.g. `./myfolder`',
16
+ description: 'The new folder path e.g. `./myfolder`. For FTP/FTPS, it will create nested folders if necessary.',
18
17
  }),
19
18
  recursive: pieces_framework_1.Property.Checkbox({
20
19
  displayName: 'Recursive',
21
20
  defaultValue: false,
22
21
  required: false,
22
+ description: 'For SFTP only: Create parent directories if they do not exist',
23
23
  }),
24
24
  },
25
25
  run(context) {
26
26
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
27
27
  var _a;
28
- const { host, port, username, password } = context.auth;
28
+ const client = yield (0, index_1.getClient)(context.auth);
29
29
  const directoryPath = context.propsValue.folderPath;
30
30
  const recursive = (_a = context.propsValue.recursive) !== null && _a !== void 0 ? _a : false;
31
- const sftp = new ssh2_sftp_client_1.default();
31
+ const protocolBackwardCompatibility = yield (0, index_1.getProtocolBackwardCompatibility)(context.auth.protocol);
32
32
  try {
33
- yield sftp.connect({
34
- host,
35
- port,
36
- username,
37
- password,
38
- readyTimeout: 15000,
39
- });
40
- yield sftp.mkdir(directoryPath, recursive);
33
+ switch (protocolBackwardCompatibility) {
34
+ case 'ftps':
35
+ case 'ftp':
36
+ yield client.ensureDir(directoryPath);
37
+ break;
38
+ default:
39
+ case 'sftp':
40
+ yield client.mkdir(directoryPath, recursive);
41
+ break;
42
+ }
41
43
  return {
42
44
  status: 'success',
43
45
  };
@@ -49,7 +51,7 @@ exports.createFolderAction = (0, pieces_framework_1.createAction)({
49
51
  };
50
52
  }
51
53
  finally {
52
- yield sftp.end();
54
+ yield (0, index_1.endClient)(client, context.auth.protocol);
53
55
  }
54
56
  });
55
57
  },
@@ -1 +1 @@
1
- {"version":3,"file":"create-folder.js","sourceRoot":"","sources":["../../../../../../../../packages/pieces/community/sftp/src/lib/actions/create-folder.ts"],"names":[],"mappings":";;;;AAAA,uCAAuC;AACvC,qEAAwE;AACxE,gFAAsC;AAEzB,QAAA,kBAAkB,GAAG,IAAA,+BAAY,EAAC;IAC7C,IAAI,EAAE,gBAAQ;IACd,IAAI,EAAE,cAAc;IACpB,WAAW,EAAE,eAAe;IAC5B,WAAW,EAAE,iCAAiC;IAC9C,KAAK,EAAE;QACL,UAAU,EAAE,2BAAQ,CAAC,SAAS,CAAC;YAC7B,WAAW,EAAE,aAAa;YAC1B,QAAQ,EAAE,IAAI;YACd,WAAW,EAAE,uCAAuC;SACrD,CAAC;QACF,SAAS,EAAE,2BAAQ,CAAC,QAAQ,CAAC;YAC3B,WAAW,EAAE,WAAW;YACxB,YAAY,EAAE,KAAK;YACnB,QAAQ,EAAE,KAAK;SAChB,CAAC;KACH;IACK,GAAG,CAAC,OAAO;;;YACf,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;YACxD,MAAM,aAAa,GAAG,OAAO,CAAC,UAAU,CAAC,UAAU,CAAC;YACpD,MAAM,SAAS,GAAG,MAAA,OAAO,CAAC,UAAU,CAAC,SAAS,mCAAI,KAAK,CAAC;YACxD,MAAM,IAAI,GAAG,IAAI,0BAAM,EAAE,CAAC;YAE1B,IAAI,CAAC;gBACH,MAAM,IAAI,CAAC,OAAO,CAAC;oBACjB,IAAI;oBACJ,IAAI;oBACJ,QAAQ;oBACR,QAAQ;oBACR,YAAY,EAAE,KAAK;iBACpB,CAAC,CAAC;gBAEH,MAAM,IAAI,CAAC,KAAK,CAAC,aAAa,EAAE,SAAS,CAAC,CAAC;gBAE3C,OAAO;oBACL,MAAM,EAAE,SAAS;iBAClB,CAAC;YACJ,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACb,OAAO;oBACL,MAAM,EAAE,OAAO;oBACf,KAAK,EAAE,GAAG;iBACX,CAAC;YACJ,CAAC;oBAAS,CAAC;gBACT,MAAM,IAAI,CAAC,GAAG,EAAE,CAAC;YACnB,CAAC;QACH,CAAC;KAAA;CACF,CAAC,CAAC"}
1
+ {"version":3,"file":"create-folder.js","sourceRoot":"","sources":["../../../../../../../../packages/pieces/community/sftp/src/lib/actions/create-folder.ts"],"names":[],"mappings":";;;;AAAE,uCAA+F;AACjG,qEAAwE;AAI3D,QAAA,kBAAkB,GAAG,IAAA,+BAAY,EAAC;IAC7C,IAAI,EAAE,gBAAQ;IACd,IAAI,EAAE,cAAc;IACpB,WAAW,EAAE,eAAe;IAC5B,WAAW,EAAE,iCAAiC;IAC9C,KAAK,EAAE;QACL,UAAU,EAAE,2BAAQ,CAAC,SAAS,CAAC;YAC7B,WAAW,EAAE,aAAa;YAC1B,QAAQ,EAAE,IAAI;YACd,WAAW,EAAE,kGAAkG;SAChH,CAAC;QACF,SAAS,EAAE,2BAAQ,CAAC,QAAQ,CAAC;YAC3B,WAAW,EAAE,WAAW;YACxB,YAAY,EAAE,KAAK;YACnB,QAAQ,EAAE,KAAK;YACf,WAAW,EAAE,+DAA+D;SAC7E,CAAC;KACH;IACK,GAAG,CAAC,OAAO;;;YACf,MAAM,MAAM,GAAG,MAAM,IAAA,iBAAS,EAAC,OAAO,CAAC,IAAI,CAAC,CAAC;YAC7C,MAAM,aAAa,GAAG,OAAO,CAAC,UAAU,CAAC,UAAU,CAAC;YACpD,MAAM,SAAS,GAAG,MAAA,OAAO,CAAC,UAAU,CAAC,SAAS,mCAAI,KAAK,CAAC;YACxD,MAAM,6BAA6B,GAAG,MAAM,IAAA,wCAAgC,EAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YACpG,IAAI,CAAC;gBACH,QAAQ,6BAA6B,EAAE,CAAC;oBACtC,KAAK,MAAM,CAAC;oBACZ,KAAK,KAAK;wBACR,MAAO,MAAoB,CAAC,SAAS,CAAC,aAAa,CAAC,CAAC;wBACrD,MAAM;oBACR,QAAQ;oBACR,KAAK,MAAM;wBACT,MAAO,MAAiB,CAAC,KAAK,CAAC,aAAa,EAAE,SAAS,CAAC,CAAC;wBACzD,MAAM;gBACV,CAAC;gBAED,OAAO;oBACL,MAAM,EAAE,SAAS;iBAClB,CAAC;YACJ,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACb,OAAO;oBACL,MAAM,EAAE,OAAO;oBACf,KAAK,EAAE,GAAG;iBACX,CAAC;YACJ,CAAC;oBAAS,CAAC;gBACT,MAAM,IAAA,iBAAS,EAAC,MAAM,EAAE,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YACjD,CAAC;QACH,CAAC;KAAA;CACF,CAAC,CAAC"}
@@ -1,4 +1,6 @@
1
1
  export declare const deleteFileAction: import("@activepieces/pieces-framework").IAction<import("@activepieces/pieces-framework").CustomAuthProperty<{
2
+ protocol: import("@activepieces/pieces-framework").StaticDropdownProperty<string, false>;
3
+ allow_unauthorized_certificates: import("@activepieces/pieces-framework").CheckboxProperty<false>;
2
4
  host: import("@activepieces/pieces-framework").ShortTextProperty<true>;
3
5
  port: import("@activepieces/pieces-framework").NumberProperty<true>;
4
6
  username: import("@activepieces/pieces-framework").ShortTextProperty<true>;
@@ -2,11 +2,20 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.deleteFileAction = void 0;
4
4
  const tslib_1 = require("tslib");
5
- const index_1 = require("../../index");
6
5
  const pieces_framework_1 = require("@activepieces/pieces-framework");
7
- const ssh2_sftp_client_1 = tslib_1.__importDefault(require("ssh2-sftp-client"));
6
+ const __1 = require("../..");
7
+ function deleteFileFromFTP(client, filePath) {
8
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
9
+ yield client.remove(filePath);
10
+ });
11
+ }
12
+ function deleteFileFromSFTP(client, filePath) {
13
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
14
+ yield client.delete(filePath);
15
+ });
16
+ }
8
17
  exports.deleteFileAction = (0, pieces_framework_1.createAction)({
9
- auth: index_1.sftpAuth,
18
+ auth: __1.sftpAuth,
10
19
  name: 'deleteFile',
11
20
  displayName: 'Delete file',
12
21
  description: 'Deletes a file at given path.',
@@ -19,30 +28,33 @@ exports.deleteFileAction = (0, pieces_framework_1.createAction)({
19
28
  },
20
29
  run(context) {
21
30
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
22
- const { host, port, username, password } = context.auth;
31
+ const client = yield (0, __1.getClient)(context.auth);
23
32
  const filePath = context.propsValue.filePath;
24
- const sftp = new ssh2_sftp_client_1.default();
33
+ const protocolBackwardCompatibility = yield (0, __1.getProtocolBackwardCompatibility)(context.auth.protocol);
25
34
  try {
26
- yield sftp.connect({
27
- host,
28
- port,
29
- username,
30
- password,
31
- readyTimeout: 15000,
32
- });
33
- yield sftp.delete(filePath);
35
+ switch (protocolBackwardCompatibility) {
36
+ case 'ftps':
37
+ case 'ftp':
38
+ yield deleteFileFromFTP(client, filePath);
39
+ break;
40
+ default:
41
+ case 'sftp':
42
+ yield deleteFileFromSFTP(client, filePath);
43
+ break;
44
+ }
34
45
  return {
35
46
  status: 'success',
36
47
  };
37
48
  }
38
49
  catch (err) {
50
+ console.error(err);
39
51
  return {
40
52
  status: 'error',
41
53
  error: err,
42
54
  };
43
55
  }
44
56
  finally {
45
- yield sftp.end();
57
+ yield (0, __1.endClient)(client, context.auth.protocol);
46
58
  }
47
59
  });
48
60
  },
@@ -1 +1 @@
1
- {"version":3,"file":"delete-file.js","sourceRoot":"","sources":["../../../../../../../../packages/pieces/community/sftp/src/lib/actions/delete-file.ts"],"names":[],"mappings":";;;;AAAA,uCAAuC;AACvC,qEAAwE;AACxE,gFAAsC;AAEzB,QAAA,gBAAgB,GAAG,IAAA,+BAAY,EAAC;IAC3C,IAAI,EAAE,gBAAQ;IACd,IAAI,EAAE,YAAY;IAClB,WAAW,EAAE,aAAa;IAC1B,WAAW,EAAE,+BAA+B;IAC5C,KAAK,EAAE;QACL,QAAQ,EAAE,2BAAQ,CAAC,SAAS,CAAC;YAC3B,WAAW,EAAE,WAAW;YACxB,QAAQ,EAAE,IAAI;YACd,WAAW,EAAE,2DAA2D;SACzE,CAAC;KACH;IACK,GAAG,CAAC,OAAO;;YACf,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;YACxD,MAAM,QAAQ,GAAG,OAAO,CAAC,UAAU,CAAC,QAAQ,CAAC;YAC7C,MAAM,IAAI,GAAG,IAAI,0BAAM,EAAE,CAAC;YAE1B,IAAI,CAAC;gBACH,MAAM,IAAI,CAAC,OAAO,CAAC;oBACjB,IAAI;oBACJ,IAAI;oBACJ,QAAQ;oBACR,QAAQ;oBACR,YAAY,EAAE,KAAK;iBACpB,CAAC,CAAC;gBAEH,MAAM,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;gBAE5B,OAAO;oBACL,MAAM,EAAE,SAAS;iBAClB,CAAC;YACJ,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACb,OAAO;oBACL,MAAM,EAAE,OAAO;oBACf,KAAK,EAAE,GAAG;iBACX,CAAC;YACJ,CAAC;oBAAS,CAAC;gBACT,MAAM,IAAI,CAAC,GAAG,EAAE,CAAC;YACnB,CAAC;QACH,CAAC;KAAA;CACF,CAAC,CAAC"}
1
+ {"version":3,"file":"delete-file.js","sourceRoot":"","sources":["../../../../../../../../packages/pieces/community/sftp/src/lib/actions/delete-file.ts"],"names":[],"mappings":";;;;AAAA,qEAAwE;AACxE,6BAAyF;AAIzF,SAAe,iBAAiB,CAAC,MAAiB,EAAE,QAAgB;;QAClE,MAAM,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IAChC,CAAC;CAAA;AAED,SAAe,kBAAkB,CAAC,MAAc,EAAE,QAAgB;;QAChE,MAAM,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IAChC,CAAC;CAAA;AAEY,QAAA,gBAAgB,GAAG,IAAA,+BAAY,EAAC;IAC3C,IAAI,EAAE,YAAQ;IACd,IAAI,EAAE,YAAY;IAClB,WAAW,EAAE,aAAa;IAC1B,WAAW,EAAE,+BAA+B;IAC5C,KAAK,EAAE;QACL,QAAQ,EAAE,2BAAQ,CAAC,SAAS,CAAC;YAC3B,WAAW,EAAE,WAAW;YACxB,QAAQ,EAAE,IAAI;YACd,WAAW,EAAE,2DAA2D;SACzE,CAAC;KACH;IACK,GAAG,CAAC,OAAO;;YACf,MAAM,MAAM,GAAG,MAAM,IAAA,aAAS,EAAC,OAAO,CAAC,IAAI,CAAC,CAAC;YAC7C,MAAM,QAAQ,GAAG,OAAO,CAAC,UAAU,CAAC,QAAQ,CAAC;YAC7C,MAAM,6BAA6B,GAAG,MAAM,IAAA,oCAAgC,EAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YACpG,IAAI,CAAC;gBACH,QAAQ,6BAA6B,EAAE,CAAC;oBACtC,KAAK,MAAM,CAAC;oBACZ,KAAK,KAAK;wBACR,MAAM,iBAAiB,CAAC,MAAmB,EAAE,QAAQ,CAAC,CAAC;wBACvD,MAAM;oBACR,QAAQ;oBACR,KAAK,MAAM;wBACT,MAAM,kBAAkB,CAAC,MAAgB,EAAE,QAAQ,CAAC,CAAC;wBACrD,MAAM;gBACV,CAAC;gBAED,OAAO;oBACL,MAAM,EAAE,SAAS;iBAClB,CAAC;YACJ,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACb,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;gBACnB,OAAO;oBACL,MAAM,EAAE,OAAO;oBACf,KAAK,EAAE,GAAG;iBACX,CAAC;YACJ,CAAC;oBAAS,CAAC;gBACT,MAAM,IAAA,aAAS,EAAC,MAAM,EAAE,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YACjD,CAAC;QACH,CAAC;KAAA;CACF,CAAC,CAAC"}
@@ -1,4 +1,6 @@
1
1
  export declare const deleteFolderAction: import("@activepieces/pieces-framework").IAction<import("@activepieces/pieces-framework").CustomAuthProperty<{
2
+ protocol: import("@activepieces/pieces-framework").StaticDropdownProperty<string, false>;
3
+ allow_unauthorized_certificates: import("@activepieces/pieces-framework").CheckboxProperty<false>;
2
4
  host: import("@activepieces/pieces-framework").ShortTextProperty<true>;
3
5
  port: import("@activepieces/pieces-framework").NumberProperty<true>;
4
6
  username: import("@activepieces/pieces-framework").ShortTextProperty<true>;
@@ -2,11 +2,25 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.deleteFolderAction = void 0;
4
4
  const tslib_1 = require("tslib");
5
- const index_1 = require("../../index");
6
5
  const pieces_framework_1 = require("@activepieces/pieces-framework");
7
- const ssh2_sftp_client_1 = tslib_1.__importDefault(require("ssh2-sftp-client"));
6
+ const __1 = require("../..");
7
+ function deleteFolderFTP(client, directoryPath, recursive) {
8
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
9
+ if (recursive) {
10
+ yield client.removeDir(directoryPath);
11
+ }
12
+ else {
13
+ yield client.removeEmptyDir(directoryPath);
14
+ }
15
+ });
16
+ }
17
+ function deleteFolderSFTP(client, directoryPath, recursive) {
18
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
19
+ yield client.rmdir(directoryPath, recursive);
20
+ });
21
+ }
8
22
  exports.deleteFolderAction = (0, pieces_framework_1.createAction)({
9
- auth: index_1.sftpAuth,
23
+ auth: __1.sftpAuth,
10
24
  name: 'deleteFolder',
11
25
  displayName: 'Delete Folder',
12
26
  description: 'Deletes an existing folder at given path.',
@@ -26,31 +40,34 @@ exports.deleteFolderAction = (0, pieces_framework_1.createAction)({
26
40
  run(context) {
27
41
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
28
42
  var _a;
29
- const { host, port, username, password } = context.auth;
43
+ const client = yield (0, __1.getClient)(context.auth);
30
44
  const directoryPath = context.propsValue.folderPath;
31
45
  const recursive = (_a = context.propsValue.recursive) !== null && _a !== void 0 ? _a : false;
32
- const sftp = new ssh2_sftp_client_1.default();
46
+ const protocolBackwardCompatibility = yield (0, __1.getProtocolBackwardCompatibility)(context.auth.protocol);
33
47
  try {
34
- yield sftp.connect({
35
- host,
36
- port,
37
- username,
38
- password,
39
- readyTimeout: 15000,
40
- });
41
- yield sftp.rmdir(directoryPath, recursive);
48
+ switch (protocolBackwardCompatibility) {
49
+ case 'ftps':
50
+ case 'ftp':
51
+ yield deleteFolderFTP(client, directoryPath, recursive);
52
+ break;
53
+ default:
54
+ case 'sftp':
55
+ yield deleteFolderSFTP(client, directoryPath, recursive);
56
+ break;
57
+ }
42
58
  return {
43
59
  status: 'success',
44
60
  };
45
61
  }
46
62
  catch (err) {
63
+ console.error(err);
47
64
  return {
48
65
  status: 'error',
49
66
  error: err,
50
67
  };
51
68
  }
52
69
  finally {
53
- yield sftp.end();
70
+ yield (0, __1.endClient)(client, context.auth.protocol);
54
71
  }
55
72
  });
56
73
  },