vtlab-generic-functions 1.0.26 → 1.0.28
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 +23 -3
- 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
|
}
|
|
@@ -193,17 +203,27 @@ class FTPClientV2 {
|
|
|
193
203
|
/**
|
|
194
204
|
* Lists files in a folder on the FTP server.
|
|
195
205
|
* @param {string} folderPath Remote folder path to list files.
|
|
206
|
+
* @param {string} sort Sort order for the files. Possible values are 'asc' or 'desc'.
|
|
196
207
|
* @returns {Promise<Array<string>>} A Pro∏”mise resolving to an array of file names in the folder.
|
|
197
208
|
* @throws {Error} If listing files fails.
|
|
198
209
|
*/
|
|
199
|
-
async listFilesInFolder(folderPath) {
|
|
210
|
+
async listFilesInFolder(folderPath, sort='asc') {
|
|
200
211
|
try {
|
|
201
212
|
if (!this._isConnected) {
|
|
202
213
|
await this.connect(this._ftpCredentials);
|
|
203
214
|
}
|
|
204
215
|
const files = await this._ftpInstance.list(folderPath);
|
|
205
|
-
|
|
206
|
-
|
|
216
|
+
|
|
217
|
+
// remove directories
|
|
218
|
+
let filteredFiles = files && files.length ? files.filter(item => item.type !== 'd') : [];
|
|
219
|
+
// sort files by date
|
|
220
|
+
let filesOnly = filteredFiles.sort((a, b) => {
|
|
221
|
+
return sort === 'asc' ? a.date - b.date : b.date - a.date;
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
// sort them from
|
|
225
|
+
return filesOnly.map((file) => file.name);
|
|
226
|
+
|
|
207
227
|
} catch (error) {
|
|
208
228
|
throw new Error(`Failed to list files in folder on FTP server: ${error.message}`);
|
|
209
229
|
}
|