w-ftp 1.0.3 → 1.0.4

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/docs/index.html CHANGED
@@ -27,7 +27,7 @@
27
27
 
28
28
  <nav >
29
29
 
30
- <h2><a href="index.html">Home</a></h2><h3>Global</h3><ul><li><a href="global.html#ftpCheckFile">ftpCheckFile</a></li><li><a href="global.html#ftpConn">ftpConn</a></li><li><a href="global.html#ftpDownload">ftpDownload</a></li><li><a href="global.html#ftpLs">ftpLs</a></li><li><a href="global.html#ftpQuit">ftpQuit</a></li><li><a href="global.html#ftpStateFile">ftpStateFile</a></li><li><a href="global.html#ftpSyncToLocal">ftpSyncToLocal</a></li><li><a href="global.html#ftpSyncToRemote">ftpSyncToRemote</a></li><li><a href="global.html#ftpUpload">ftpUpload</a></li><li><a href="global.html#WFtp">WFtp</a></li></ul>
30
+ <h2><a href="index.html">Home</a></h2><h3>Global</h3><ul><li><a href="global.html#conn">conn</a></li><li><a href="global.html#download">download</a></li><li><a href="global.html#isFile">isFile</a></li><li><a href="global.html#isFolder">isFolder</a></li><li><a href="global.html#ls">ls</a></li><li><a href="global.html#quit">quit</a></li><li><a href="global.html#stateFile">stateFile</a></li><li><a href="global.html#syncToLocal">syncToLocal</a></li><li><a href="global.html#syncToRemote">syncToRemote</a></li><li><a href="global.html#upload">upload</a></li><li><a href="global.html#WFtp">WFtp</a></li></ul>
31
31
  </nav>
32
32
 
33
33
  <div id="main">
@@ -68,7 +68,7 @@
68
68
  <br class="clear">
69
69
 
70
70
  <footer>
71
- Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.10</a> on Sat Jul 23 2022 21:57:53 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
71
+ Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.10</a> on Sun Jul 24 2022 12:32:49 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
72
72
  </footer>
73
73
 
74
74
  <script>prettyPrint();</script>
@@ -27,7 +27,7 @@
27
27
 
28
28
  <nav >
29
29
 
30
- <h2><a href="index.html">Home</a></h2><h3>Global</h3><ul><li><a href="global.html#ftpCheckFile">ftpCheckFile</a></li><li><a href="global.html#ftpConn">ftpConn</a></li><li><a href="global.html#ftpDownload">ftpDownload</a></li><li><a href="global.html#ftpLs">ftpLs</a></li><li><a href="global.html#ftpQuit">ftpQuit</a></li><li><a href="global.html#ftpStateFile">ftpStateFile</a></li><li><a href="global.html#ftpSyncToLocal">ftpSyncToLocal</a></li><li><a href="global.html#ftpSyncToRemote">ftpSyncToRemote</a></li><li><a href="global.html#ftpUpload">ftpUpload</a></li><li><a href="global.html#WFtp">WFtp</a></li></ul>
30
+ <h2><a href="index.html">Home</a></h2><h3>Global</h3><ul><li><a href="global.html#conn">conn</a></li><li><a href="global.html#download">download</a></li><li><a href="global.html#isFile">isFile</a></li><li><a href="global.html#isFolder">isFolder</a></li><li><a href="global.html#ls">ls</a></li><li><a href="global.html#quit">quit</a></li><li><a href="global.html#stateFile">stateFile</a></li><li><a href="global.html#syncToLocal">syncToLocal</a></li><li><a href="global.html#syncToRemote">syncToRemote</a></li><li><a href="global.html#upload">upload</a></li><li><a href="global.html#WFtp">WFtp</a></li></ul>
31
31
  </nav>
32
32
 
33
33
  <div id="main">
@@ -626,7 +626,7 @@ Ftp.prototype.put = function(from, destination, callback) {
626
626
  // })
627
627
 
628
628
  socket.on('drain', () => {
629
- console.log('drain')
629
+ // console.log('drain')
630
630
  if (from.length > pointer + SLICE) {
631
631
  newBuf = from.slice(pointer, pointer + SLICE)
632
632
  pointer += SLICE
@@ -811,11 +811,14 @@ Ftp.prototype.getPasvSocket = function(callback = NOOP) {
811
811
  */
812
812
  Ftp.prototype.ls = function(filePath, callback) {
813
813
  function entriesToList(err, entries) {
814
+ // console.log('entriesToList', err, entries)
814
815
  if (err) {
815
816
  return callback(err)
816
817
  }
817
818
 
819
+ //ListingParser.parseFtpEntries是基於parse-listing解析, 但原始數據是ls而來, 本身就沒有到秒, 故只有類似dir提供的粗略時間, 無法像fs.statSync提供精確的產生與最新變更時間
818
820
  ListingParser.parseFtpEntries(entries.text || entries, (err, files) => {
821
+ // console.log('ListingParser.parseFtpEntries', err, files)
819
822
  if (err) {
820
823
  return callback(err)
821
824
  }
@@ -834,6 +837,7 @@ Ftp.prototype.ls = function(filePath, callback) {
834
837
  }
835
838
  else {
836
839
  this.raw('stat', filePath, (err, data) => {
840
+ // console.log('filePath', filePath, data)
837
841
  // We might be connected to a server that doesn't support the
838
842
  // 'STAT' command, which is set as default. We use 'LIST' instead,
839
843
  // and we set the variable `useList` to true, to avoid extra round
@@ -912,7 +916,7 @@ module.exports = Ftp
912
916
  <br class="clear">
913
917
 
914
918
  <footer>
915
- Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.10</a> on Sat Jul 23 2022 21:57:53 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
919
+ Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.10</a> on Sun Jul 24 2022 12:32:49 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
916
920
  </footer>
917
921
 
918
922
  <script>prettyPrint();</script>
package/g-download.mjs CHANGED
@@ -24,18 +24,32 @@ async function test_dw() {
24
24
  password: st.dw.password,
25
25
  })
26
26
 
27
- let fps = await ftp.ls('.')
28
- console.log('ftp.ls', fps[0], fps.length)
27
+ async function core() {
29
28
 
30
- r = await ftp.download('./DECL_20210805055044.csv', './_test_download_client/DECL_20210805055044.csv', (p) => {
31
- console.log('ftp.download p', p.name, p.progress)
32
- })
33
- console.log('ftp.download', r)
29
+ let fps = await ftp.ls('.')
30
+ console.log('ftp.ls', fps[0], fps.length)
34
31
 
35
- r = await ftp.syncToLocal('.', './_test_download_client', (p) => {
36
- console.log('ftp.syncToLocal p', p.name, p.progress)
37
- })
38
- console.log('ftp.syncToLocal', r)
32
+ r = await ftp.isFile('./DECL_20210805055044.csv')
33
+ console.log('ftp.isFile', r)
34
+
35
+ r = await ftp.isFolder('./DECL_20210805055044.csv')
36
+ console.log('ftp.isFolder', r)
37
+
38
+ r = await ftp.download('./DECL_20210805055044.csv', './_test_download_client/DECL_20210805055044.csv', (p) => {
39
+ console.log('ftp.download p', p.name, p.progress)
40
+ })
41
+ console.log('ftp.download', r)
42
+
43
+ r = await ftp.syncToLocal('.', './_test_download_client', (p) => {
44
+ console.log('ftp.syncToLocal p', p.name, p.progress)
45
+ })
46
+ console.log('ftp.syncToLocal', r)
47
+
48
+ }
49
+ await core()
50
+ .catch((err) => {
51
+ console.log(err)
52
+ })
39
53
 
40
54
  r = await ftp.quit()
41
55
  console.log('ftp.quit', r)
@@ -56,6 +70,8 @@ test_dw()
56
70
  // groupPermissions: { read: true, write: true, exec: false },
57
71
  // otherPermissions: { read: true, write: true, exec: false }
58
72
  // } 74
73
+ // ftp.isFile false
74
+ // ftp.isFolder false
59
75
  // ftp.download p DECL_20210805055044.csv 4.7320871554333515
60
76
  // ftp.download p DECL_20210805055044.csv 9.464174310866703
61
77
  // ftp.download p DECL_20210805055044.csv 14.196261466300053
package/g-upload.mjs CHANGED
@@ -24,18 +24,32 @@ async function test_up() {
24
24
  password: st.up.password,
25
25
  })
26
26
 
27
- let fps = await ftp.ls('.')
28
- console.log('ftp.ls', fps[0], fps.length)
27
+ async function core() {
29
28
 
30
- r = await ftp.upload('./_test_upload_client/DECL_20210805055044.csv', './DECL_20210805055044.csv', (p) => {
31
- console.log('ftp.upload p', p.name, p.progress)
32
- })
33
- console.log('ftp.upload', r)
29
+ let fps = await ftp.ls('.')
30
+ console.log('ftp.ls', fps[0], fps.length)
34
31
 
35
- r = await ftp.syncToRemote('./_test_upload_client', '.', (p) => {
36
- console.log('ftp.syncToRemote p', p.name, p.progress)
37
- })
38
- console.log('ftp.syncToRemote', r)
32
+ r = await ftp.isFile('./DECL_20210805055044.csv')
33
+ console.log('ftp.isFile', r)
34
+
35
+ r = await ftp.isFolder('./DECL_20210805055044.csv')
36
+ console.log('ftp.isFolder', r)
37
+
38
+ r = await ftp.upload('./_test_upload_client/DECL_20210805055044.csv', './DECL_20210805055044.csv', (p) => {
39
+ console.log('ftp.upload p', p.name, p.progress)
40
+ })
41
+ console.log('ftp.upload', r)
42
+
43
+ r = await ftp.syncToRemote('./_test_upload_client', '.', (p) => {
44
+ console.log('ftp.syncToRemote p', p.name, p.progress)
45
+ })
46
+ console.log('ftp.syncToRemote', r)
47
+
48
+ }
49
+ await core()
50
+ .catch((err) => {
51
+ console.log(err)
52
+ })
39
53
 
40
54
  r = await ftp.quit()
41
55
  console.log('ftp.quit', r)
@@ -56,8 +70,9 @@ test_up()
56
70
  // groupPermissions: { read: true, write: true, exec: false },
57
71
  // otherPermissions: { read: true, write: true, exec: false }
58
72
  // } 73
73
+ // ftp.isFile false
74
+ // ftp.isFolder false
59
75
  // ftp.upload p DECL_20210805055044.csv 75.71339448693362
60
- // drain
61
76
  // ftp.upload p DECL_20210805055044.csv 100
62
77
  // ftp.upload ok
63
78
  // ftp.syncToRemote { num: 0, files: [] }
package/package.json CHANGED
@@ -1,15 +1,16 @@
1
1
  {
2
2
  "name": "w-ftp",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "main": "dist/w-ftp.umd.js",
5
5
  "dependencies": {
6
+ "dayjs": "^1.11.4",
6
7
  "debug": "^4.3.4",
7
8
  "ftp-response-parser": "^1.0.1",
9
+ "lodash": "^4.17.21",
8
10
  "once": "^1.4.0",
9
11
  "parse-listing": "^1.1.3",
10
12
  "stream-combiner": "^0.2.2",
11
13
  "unorm": "^1.6.0",
12
- "lodash": "^4.17.21",
13
14
  "wsemi": "^1.6.69"
14
15
  },
15
16
  "devDependencies": {
package/src/WFtp.mjs CHANGED
@@ -20,6 +20,7 @@ import fsTreeFolder from 'wsemi/src/fsTreeFolder.mjs'
20
20
  import fsIsFolder from 'wsemi/src/fsIsFolder.mjs'
21
21
  import fsIsFile from 'wsemi/src/fsIsFile.mjs'
22
22
  import fsCreateFolder from 'wsemi/src/fsCreateFolder.mjs'
23
+ import ot from 'dayjs'
23
24
  import Jsftp from './jsftp.js'
24
25
 
25
26
 
@@ -60,7 +61,7 @@ import Jsftp from './jsftp.js'
60
61
  * })
61
62
  *
62
63
  */
63
- async function ftpConn(opt = {}) {
64
+ async function conn(opt = {}) {
64
65
  return null
65
66
  }
66
67
 
@@ -99,7 +100,7 @@ async function ftpConn(opt = {}) {
99
100
  * })
100
101
  *
101
102
  */
102
- async function ftpLs(fdRemote = '.') {
103
+ async function ls(fdRemote = '.') {
103
104
  return null
104
105
  }
105
106
 
@@ -135,7 +136,7 @@ async function ftpLs(fdRemote = '.') {
135
136
  * console.log(err)
136
137
  * })
137
138
  */
138
- async function ftpQuit() {
139
+ async function quit() {
139
140
  return null
140
141
  }
141
142
 
@@ -173,7 +174,7 @@ async function ftpQuit() {
173
174
  * console.log(err)
174
175
  * })
175
176
  */
176
- async function ftpStateFile(fpRemote) {
177
+ async function stateFile(fpRemote) {
177
178
  return null
178
179
  }
179
180
 
@@ -199,8 +200,8 @@ async function ftpStateFile(fpRemote) {
199
200
  * password: st.up.password,
200
201
  * })
201
202
  *
202
- * r = await ftp.checkFile('./_test_upload_client/DECL_20210805055044.csv')
203
- * console.log('ftp.checkFile', r)
203
+ * r = await ftp.isFile('./_test_upload_client/DECL_20210805055044.csv')
204
+ * console.log('ftp.isFile', r)
204
205
  *
205
206
  * r = await ftp.quit()
206
207
  * console.log('ftp.quit', r)
@@ -211,7 +212,45 @@ async function ftpStateFile(fpRemote) {
211
212
  * console.log(err)
212
213
  * })
213
214
  */
214
- async function ftpCheckFile(fpRemote) {
215
+ async function isFile(fpRemote) {
216
+ return null
217
+ }
218
+
219
+
220
+ /**
221
+ * 確認伺服器指定資料夾是否存在
222
+ *
223
+ * @param {String} opt.fpRemote 輸入伺服器上指定資料夾字串
224
+ * @return {Promise} 回傳Promise,resolve回傳指定資料夾是否存在布林值,reject回傳錯誤訊息
225
+ * @example
226
+ * import WFtp from './src/WFtp.mjs'
227
+ *
228
+ * async function test() {
229
+ * let r
230
+ *
231
+ * let ftp = WFtp()
232
+ * // console.log('ftp', ftp)
233
+ *
234
+ * await ftp.conn({
235
+ * hostname: st.up.hostname,
236
+ * port: st.up.port,
237
+ * username: st.up.username,
238
+ * password: st.up.password,
239
+ * })
240
+ *
241
+ * r = await ftp.isFolder('./_test_upload_client')
242
+ * console.log('ftp.isFolder', r)
243
+ *
244
+ * r = await ftp.quit()
245
+ * console.log('ftp.quit', r)
246
+ *
247
+ * }
248
+ * test()
249
+ * .catch((err) => {
250
+ * console.log(err)
251
+ * })
252
+ */
253
+ async function isFolder(fpRemote) {
215
254
  return null
216
255
  }
217
256
 
@@ -253,7 +292,7 @@ async function ftpCheckFile(fpRemote) {
253
292
  * console.log(err)
254
293
  * })
255
294
  */
256
- async function ftpDownload(fpRemote, fpLocal, cbProcess = null) {
295
+ async function download(fpRemote, fpLocal, cbProcess = null) {
257
296
  return null
258
297
  }
259
298
 
@@ -295,7 +334,7 @@ async function ftpDownload(fpRemote, fpLocal, cbProcess = null) {
295
334
  * console.log(err)
296
335
  * })
297
336
  */
298
- async function ftpUpload(fpLocal, fpRemote, cbProcess) {
337
+ async function upload(fpLocal, fpRemote, cbProcess) {
299
338
  return null
300
339
  }
301
340
 
@@ -337,7 +376,7 @@ async function ftpUpload(fpLocal, fpRemote, cbProcess) {
337
376
  * console.log(err)
338
377
  * })
339
378
  */
340
- async function ftpSyncToLocal(fdRemote, fdLocal, cbProcess) {
379
+ async function syncToLocal(fdRemote, fdLocal, cbProcess) {
341
380
  return null
342
381
  }
343
382
 
@@ -379,7 +418,7 @@ async function ftpSyncToLocal(fdRemote, fdLocal, cbProcess) {
379
418
  * console.log(err)
380
419
  * })
381
420
  */
382
- async function ftpSyncToRemote(fdLocal, fdRemote, cbProcess) {
421
+ async function syncToRemote(fdLocal, fdRemote, cbProcess) {
383
422
  return null
384
423
  }
385
424
 
@@ -387,11 +426,11 @@ async function ftpSyncToRemote(fdLocal, fdRemote, cbProcess) {
387
426
  /**
388
427
  * 操作FTP,包含連線、下載、資料夾內檔案同步下載、上傳、資料夾內檔案同步上傳等功能
389
428
  *
390
- * @returns {Object} 回傳FTP操作物件,包含conn、ls、stateFile、checkFile、download、syncToLocal、syncToRemote、upload、quit。
429
+ * @returns {Object} 回傳FTP操作物件,包含conn、ls、stateFile、isFile、download、syncToLocal、syncToRemote、upload、quit。
391
430
  * @example
392
431
  * import WFtp from './src/WFtp.mjs'
393
432
  *
394
- * async function test_up() {
433
+ * async function test_dw() {
395
434
  * let r
396
435
  *
397
436
  * let ftp = WFtp()
@@ -404,46 +443,73 @@ async function ftpSyncToRemote(fdLocal, fdRemote, cbProcess) {
404
443
  * password: `{password}`,
405
444
  * })
406
445
  *
407
- * let fps = await ftp.ls('.')
408
- * console.log('ftp.ls', fps[0], fps.length)
446
+ * async function core() {
409
447
  *
410
- * r = await ftp.upload('./_test_upload_client/DECL_20210805055044.csv', './DECL_20210805055044.csv', (p) => {
411
- * console.log('ftp.upload p', p.name, p.progress)
412
- * })
413
- * console.log('ftp.upload', r)
448
+ * let fps = await ftp.ls('.')
449
+ * console.log('ftp.ls', fps[0], fps.length)
414
450
  *
415
- * r = await ftp.syncToRemote('./_test_upload_client', '.', (p) => {
416
- * console.log('ftp.syncToRemote p', p.name, p.progress)
417
- * })
418
- * console.log('ftp.syncToRemote', r)
451
+ * r = await ftp.download('./DECL_20210805055044.csv', './_test_download_client/DECL_20210805055044.csv', (p) => {
452
+ * console.log('ftp.download p', p.name, p.progress)
453
+ * })
454
+ * console.log('ftp.download', r)
455
+ *
456
+ * r = await ftp.syncToLocal('.', './_test_download_client', (p) => {
457
+ * console.log('ftp.syncToLocal p', p.name, p.progress)
458
+ * })
459
+ * console.log('ftp.syncToLocal', r)
460
+ *
461
+ * }
462
+ * await core()
463
+ * .catch((err) => {
464
+ * console.log(err)
465
+ * })
419
466
  *
420
467
  * r = await ftp.quit()
421
468
  * console.log('ftp.quit', r)
422
469
  *
423
470
  * }
424
- * test_up()
471
+ * test_dw()
425
472
  * .catch((err) => {
426
473
  * console.log(err)
427
474
  * })
428
475
  * // ftp.ls {
429
476
  * // name: 'DECL_202108.csv',
430
477
  * // type: 0,
431
- * // time: 1658366760000,
478
+ * // time: 1658302140000,
432
479
  * // size: '218690',
433
480
  * // owner: 'ftp',
434
481
  * // group: 'ftp',
435
482
  * // userPermissions: { read: true, write: true, exec: false },
436
483
  * // groupPermissions: { read: true, write: true, exec: false },
437
484
  * // otherPermissions: { read: true, write: true, exec: false }
438
- * // } 73
439
- * // ftp.upload p DECL_20210805055044.csv 75.71339448693362
440
- * // drain
441
- * // ftp.upload p DECL_20210805055044.csv 100
442
- * // ftp.upload ok
443
- * // ftp.syncToRemote { num: 0, files: [] }
485
+ * // } 74
486
+ * // ftp.download p DECL_20210805055044.csv 4.7320871554333515
487
+ * // ftp.download p DECL_20210805055044.csv 9.464174310866703
488
+ * // ftp.download p DECL_20210805055044.csv 14.196261466300053
489
+ * // ftp.download p DECL_20210805055044.csv 18.928348621733406
490
+ * // ftp.download p DECL_20210805055044.csv 23.660435777166754
491
+ * // ftp.download p DECL_20210805055044.csv 28.392522932600105
492
+ * // ftp.download p DECL_20210805055044.csv 33.12461008803346
493
+ * // ftp.download p DECL_20210805055044.csv 37.85669724346681
494
+ * // ftp.download p DECL_20210805055044.csv 42.58878439890016
495
+ * // ftp.download p DECL_20210805055044.csv 47.32087155433351
496
+ * // ftp.download p DECL_20210805055044.csv 52.05295870976686
497
+ * // ftp.download p DECL_20210805055044.csv 56.78504586520021
498
+ * // ftp.download p DECL_20210805055044.csv 61.517133020633565
499
+ * // ftp.download p DECL_20210805055044.csv 66.24922017606691
500
+ * // ftp.download p DECL_20210805055044.csv 70.98130733150026
501
+ * // ftp.download p DECL_20210805055044.csv 75.71339448693362
502
+ * // ftp.download p DECL_20210805055044.csv 80.44548164236697
503
+ * // ftp.download p DECL_20210805055044.csv 85.17756879780032
504
+ * // ftp.download p DECL_20210805055044.csv 89.90965595323367
505
+ * // ftp.download p DECL_20210805055044.csv 94.64174310866701
506
+ * // ftp.download p DECL_20210805055044.csv 99.37383026410038
507
+ * // ftp.download p DECL_20210805055044.csv 100
508
+ * // ftp.download ok
509
+ * // ftp.syncToLocal { num: 0, files: [] }
444
510
  * // ftp.quit { code: 221, text: '221 Goodbye.', isMark: false, isError: false }
445
511
  *
446
- * async function test_dw() {
512
+ * async function test_up() {
447
513
  * let r
448
514
  *
449
515
  * let ftp = WFtp()
@@ -456,76 +522,65 @@ async function ftpSyncToRemote(fdLocal, fdRemote, cbProcess) {
456
522
  * password: `{password}`,
457
523
  * })
458
524
  *
459
- * let fps = await ftp.ls('.')
460
- * console.log('ftp.ls', fps[0], fps.length)
525
+ * async function core() {
461
526
  *
462
- * r = await ftp.download('./DECL_20210805055044.csv', './_test_download_client/DECL_20210805055044.csv', (p) => {
463
- * console.log('ftp.download p', p.name, p.progress)
464
- * })
465
- * console.log('ftp.download', r)
527
+ * let fps = await ftp.ls('.')
528
+ * console.log('ftp.ls', fps[0], fps.length)
466
529
  *
467
- * r = await ftp.syncToLocal('.', './_test_download_client', (p) => {
468
- * console.log('ftp.syncToLocal p', p.name, p.progress)
469
- * })
470
- * console.log('ftp.syncToLocal', r)
530
+ * r = await ftp.upload('./_test_upload_client/DECL_20210805055044.csv', './DECL_20210805055044.csv', (p) => {
531
+ * console.log('ftp.upload p', p.name, p.progress)
532
+ * })
533
+ * console.log('ftp.upload', r)
534
+ *
535
+ * r = await ftp.syncToRemote('./_test_upload_client', '.', (p) => {
536
+ * console.log('ftp.syncToRemote p', p.name, p.progress)
537
+ * })
538
+ * console.log('ftp.syncToRemote', r)
539
+ *
540
+ * }
541
+ * await core()
542
+ * .catch((err) => {
543
+ * console.log(err)
544
+ * })
471
545
  *
472
546
  * r = await ftp.quit()
473
547
  * console.log('ftp.quit', r)
474
548
  *
475
549
  * }
476
- * test_dw()
550
+ * test_up()
477
551
  * .catch((err) => {
478
552
  * console.log(err)
479
553
  * })
480
554
  * // ftp.ls {
481
555
  * // name: 'DECL_202108.csv',
482
556
  * // type: 0,
483
- * // time: 1658302140000,
557
+ * // time: 1658366760000,
484
558
  * // size: '218690',
485
559
  * // owner: 'ftp',
486
560
  * // group: 'ftp',
487
561
  * // userPermissions: { read: true, write: true, exec: false },
488
562
  * // groupPermissions: { read: true, write: true, exec: false },
489
563
  * // otherPermissions: { read: true, write: true, exec: false }
490
- * // } 74
491
- * // ftp.download p DECL_20210805055044.csv 4.7320871554333515
492
- * // ftp.download p DECL_20210805055044.csv 9.464174310866703
493
- * // ftp.download p DECL_20210805055044.csv 14.196261466300053
494
- * // ftp.download p DECL_20210805055044.csv 18.928348621733406
495
- * // ftp.download p DECL_20210805055044.csv 23.660435777166754
496
- * // ftp.download p DECL_20210805055044.csv 28.392522932600105
497
- * // ftp.download p DECL_20210805055044.csv 33.12461008803346
498
- * // ftp.download p DECL_20210805055044.csv 37.85669724346681
499
- * // ftp.download p DECL_20210805055044.csv 42.58878439890016
500
- * // ftp.download p DECL_20210805055044.csv 47.32087155433351
501
- * // ftp.download p DECL_20210805055044.csv 52.05295870976686
502
- * // ftp.download p DECL_20210805055044.csv 56.78504586520021
503
- * // ftp.download p DECL_20210805055044.csv 61.517133020633565
504
- * // ftp.download p DECL_20210805055044.csv 66.24922017606691
505
- * // ftp.download p DECL_20210805055044.csv 70.98130733150026
506
- * // ftp.download p DECL_20210805055044.csv 75.71339448693362
507
- * // ftp.download p DECL_20210805055044.csv 80.44548164236697
508
- * // ftp.download p DECL_20210805055044.csv 85.17756879780032
509
- * // ftp.download p DECL_20210805055044.csv 89.90965595323367
510
- * // ftp.download p DECL_20210805055044.csv 94.64174310866701
511
- * // ftp.download p DECL_20210805055044.csv 99.37383026410038
512
- * // ftp.download p DECL_20210805055044.csv 100
513
- * // ftp.download ok
514
- * // ftp.syncToLocal { num: 0, files: [] }
564
+ * // } 73
565
+ * // ftp.upload p DECL_20210805055044.csv 75.71339448693362
566
+ * // ftp.upload p DECL_20210805055044.csv 100
567
+ * // ftp.upload ok
568
+ * // ftp.syncToRemote { num: 0, files: [] }
515
569
  * // ftp.quit { code: 221, text: '221 Goodbye.', isMark: false, isError: false }
516
570
  *
517
571
  */
518
572
  function WFtp() {
519
573
  let doc = {
520
- doc_ftpConn: ftpConn,
521
- doc_ftpLs: ftpLs,
522
- doc_ftpQuit: ftpQuit,
523
- doc_ftpStateFile: ftpStateFile,
524
- doc_ftpCheckFile: ftpCheckFile,
525
- doc_ftpDownload: ftpDownload,
526
- doc_ftpUpload: ftpUpload,
527
- doc_ftpSyncToLocal: ftpSyncToLocal,
528
- doc_ftpSyncToRemote: ftpSyncToRemote,
574
+ doc_conn: conn,
575
+ doc_ls: ls,
576
+ doc_quit: quit,
577
+ doc_stateFile: stateFile,
578
+ doc_isFile: isFile,
579
+ doc_isFolder: isFolder,
580
+ doc_download: download,
581
+ doc_upload: upload,
582
+ doc_syncToLocal: syncToLocal,
583
+ doc_syncToRemote: syncToRemote,
529
584
  }
530
585
 
531
586
  function WFtpCore() {
@@ -600,6 +655,12 @@ function WFtp() {
600
655
  pm.reject(err)
601
656
  }
602
657
  else {
658
+ res = map(res, (v) => {
659
+ let d = ot(v.time) //jsfpt解析時間係基於ls, 其檔案變更時間精度只至分而沒有秒, 故無法提供精確的檔案變更時間
660
+ v.ctime = d.format('YYYY-MM-DDTHH:mm:ssZ') //添加UTC時間
661
+ v.isFolder = ftpIsFolderCore(v)
662
+ return v
663
+ })
603
664
  pm.resolve(res)
604
665
  }
605
666
  })
@@ -652,13 +713,56 @@ function WFtp() {
652
713
  }
653
714
 
654
715
 
655
- async function ftpCheckFile(fpRemote) {
716
+ function ftpIsFolderCore(file) {
717
+
718
+ //check
719
+ if (!iseobj(file)) {
720
+ return false
721
+ }
722
+
723
+ //type
724
+ let type = get(file, 'type', -1)
725
+
726
+ //b
727
+ let b = type === 1
728
+
729
+ return b
730
+ }
731
+
732
+
733
+ function ftpIsFileCore(file) {
734
+
735
+ //check
736
+ if (!iseobj(file)) {
737
+ return false
738
+ }
739
+
740
+ //type
741
+ let type = get(file, 'type', -1)
742
+
743
+ //b
744
+ let b = type === 0
745
+
746
+ return b
747
+ }
748
+
749
+
750
+ async function ftpIsFolder(fpRemote) {
656
751
 
657
752
  //ftpStateFile
658
753
  let file = await ftpStateFile(fpRemote)
659
754
 
660
- //b
661
- let b = iseobj(file)
755
+ //ftpIsFolderCore
756
+ let b = ftpIsFolderCore(file)
757
+
758
+ return b
759
+ }
760
+
761
+
762
+ async function ftpIsFile(fpRemote) {
763
+
764
+ //ftpIsFileCore
765
+ let b = await ftpIsFileCore(fpRemote)
662
766
 
663
767
  return b
664
768
  }
@@ -699,6 +803,22 @@ function WFtp() {
699
803
  let file = await ftpStateFile(fpRemote)
700
804
  // console.log('file', file)
701
805
 
806
+ //ftpIsFileCore
807
+ let b = await ftpIsFileCore(file)
808
+ // console.log('b', b)
809
+
810
+ //check
811
+ if (!b) {
812
+ pm.reject(`fpRemote[${fpRemote}] is not a file`)
813
+ return pm
814
+ }
815
+
816
+ //check
817
+ if (!iseobj(file)) {
818
+ pm.reject(`fpRemote[${fpRemote}] does not have information`)
819
+ return pm
820
+ }
821
+
702
822
  //fileSize
703
823
  let fileSize = get(file, 'size')
704
824
 
@@ -862,11 +982,9 @@ function WFtp() {
862
982
 
863
983
  //ftpLs
864
984
  let fsRemote = await ftpLs(fdRemote)
865
- // fsRemote = map(fsRemote, (v) => {
866
- // let d = dayjs(v.time)
867
- // v.stat = d.format('YYYY-MM-DDTHH:mm:ss')
868
- // return v
869
- // })
985
+ fsRemote = filter(fsRemote, (v) => {
986
+ return !v.isFolder
987
+ })
870
988
  // console.log('fsRemote', fsRemote)
871
989
 
872
990
  //check fdLocal
@@ -1039,7 +1157,8 @@ function WFtp() {
1039
1157
  conn: ftpConn,
1040
1158
  ls: ftpLs,
1041
1159
  stateFile: ftpStateFile,
1042
- checkFile: ftpCheckFile,
1160
+ isFile: ftpIsFile,
1161
+ isFolder: ftpIsFolder,
1043
1162
  download: ftpDownload,
1044
1163
  syncToLocal: ftpSyncToLocal,
1045
1164
  syncToRemote: ftpSyncToRemote,