vtlab-generic-functions 1.0.27 → 1.0.29
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/ftp/ftpClientClass.js +32 -0
- package/package.json +1 -1
package/ftp/ftpClientClass.js
CHANGED
|
@@ -62,6 +62,16 @@ class FTPClientV2 {
|
|
|
62
62
|
case "ftp":
|
|
63
63
|
case "sftp":
|
|
64
64
|
default:
|
|
65
|
+
// remove commands not allowed
|
|
66
|
+
if (config.username) {
|
|
67
|
+
delete config.username;
|
|
68
|
+
}
|
|
69
|
+
if (config.port) {
|
|
70
|
+
delete config.port;
|
|
71
|
+
}
|
|
72
|
+
if (config.forcePasv === undefined) {
|
|
73
|
+
config.forcePasv = true;
|
|
74
|
+
}
|
|
65
75
|
this._ftpInstance = new promiseFTP();
|
|
66
76
|
break;
|
|
67
77
|
}
|
|
@@ -218,6 +228,28 @@ class FTPClientV2 {
|
|
|
218
228
|
throw new Error(`Failed to list files in folder on FTP server: ${error.message}`);
|
|
219
229
|
}
|
|
220
230
|
}
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* Moves a file inside the FTP server.
|
|
234
|
+
* @param {string} ftpPathOrigin The original path of the file.
|
|
235
|
+
* @param {string} ftpPathDestination The new path of the file.
|
|
236
|
+
* @returns {Promise<Object>} A Promise resolving to an object with move status.
|
|
237
|
+
* @throws {Error} If move fails.
|
|
238
|
+
*/
|
|
239
|
+
async moveFileInsideFTP(ftpPathOrigin, ftpPathDestination) {
|
|
240
|
+
try {
|
|
241
|
+
if (!this._isConnected) {
|
|
242
|
+
await this.connect(this._ftpCredentials);
|
|
243
|
+
}
|
|
244
|
+
await this._ftpInstance.put(ftpPathOrigin, ftpPathDestination);
|
|
245
|
+
await this.deleteFile(ftpPathOrigin);
|
|
246
|
+
return { code: 200, message: "FTP successful moved" };
|
|
247
|
+
} catch (error) {
|
|
248
|
+
throw new Error(`Failed to move file inside FTP server: ${error.message}`);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
|
|
221
253
|
}
|
|
222
254
|
|
|
223
255
|
module.exports = {
|