w-ftp 1.0.1 → 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/src/WFtp.mjs CHANGED
@@ -20,55 +20,568 @@ 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 Jsftp from 'jsftp'
23
+ import ot from 'dayjs'
24
24
  import Jsftp from './jsftp.js'
25
- console.log('Jsftp', Jsftp)
26
25
 
27
26
 
28
27
  /**
29
- * 指定FTP伺服器資料夾內檔案並自動同步至本機,只能用於Windows作業系統
28
+ * 連線至FPT伺服器
30
29
  *
31
- * @param {String} fp 輸入檔案路徑字串
32
30
  * @param {Object} [opt={}] 輸入設定物件,預設{}
33
- * @param {String} [opt.ver='4.8'] 輸入調用windows程序之Net Framework版本字串,可有'4.5'、'4.6'、'4.7.2'與'4.8',預設'4.8'
34
- * @returns {Promise} 回傳Promise,resolve回傳成功訊息,reject回傳錯誤訊息
31
+ * @param {String} opt.hostname='' 輸入hostname字串
32
+ * @param {Number} opt.port='' 輸入port正整數
33
+ * @param {String} opt.username='' 輸入帳號字串
34
+ * @param {String} opt.password='' 輸入密碼字串
35
+ * @return {Promise} 回傳Promise,resolve回傳成功訊息,reject回傳錯誤訊息
35
36
  * @example
36
37
  * import WFtp from './src/WFtp.mjs'
37
38
  *
38
39
  * async function test() {
40
+ * let r
39
41
  *
40
- * //fp
41
- * let fp = './g.mseed'
42
- *
43
- * //WFtp
44
- * let r = await WFtp(fp)
45
- * console.log(r)
46
- * // [
47
- * // {
48
- * // name: 'SE.RST01.00.HNE.D.2020-09-17T013552.000000.csv',
49
- * // path: null,
50
- * // data: { heads: [Object], records: [Array] }
51
- * // },
52
- * // {
53
- * // name: 'SE.RST01.00.HNN.D.2020-09-17T013552.000000.csv',
54
- * // path: null,
55
- * // data: { heads: [Object], records: [Array] }
56
- * // },
57
- * // {
58
- * // name: 'SE.RST01.00.HNZ.D.2020-09-17T013552.000000.csv',
59
- * // path: null,
60
- * // data: { heads: [Object], records: [Array] }
61
- * // }
62
- * // ]
42
+ * let ftp = WFtp()
43
+ * // console.log('ftp', ftp)
44
+ *
45
+ * await ftp.conn({
46
+ * hostname: st.up.hostname,
47
+ * port: st.up.port,
48
+ * username: st.up.username,
49
+ * password: st.up.password,
50
+ * })
51
+ *
52
+ * //actions
53
+ *
54
+ * r = await ftp.quit()
55
+ * console.log('ftp.quit', r)
63
56
  *
64
57
  * }
65
58
  * test()
66
59
  * .catch((err) => {
67
- * console.log('catch', err)
60
+ * console.log(err)
68
61
  * })
69
62
  *
70
63
  */
64
+ async function conn(opt = {}) {
65
+ return null
66
+ }
67
+
68
+
69
+ /**
70
+ * 遍歷伺服器上指定資料夾內檔案清單資訊
71
+ *
72
+ * @param {String} opt.fdRemote 輸入伺服器上指定資料夾字串
73
+ * @return {Promise} 回傳Promise,resolve回傳檔案清單資訊,reject回傳錯誤訊息
74
+ * @example
75
+ * import WFtp from './src/WFtp.mjs'
76
+ *
77
+ * async function test() {
78
+ * let r
79
+ *
80
+ * let ftp = WFtp()
81
+ * // console.log('ftp', ftp)
82
+ *
83
+ * await ftp.conn({
84
+ * hostname: st.up.hostname,
85
+ * port: st.up.port,
86
+ * username: st.up.username,
87
+ * password: st.up.password,
88
+ * })
89
+ *
90
+ * let fps = await ftp.ls('.')
91
+ * console.log('ftp.ls', fps[0], fps.length)
92
+ *
93
+ * r = await ftp.quit()
94
+ * console.log('ftp.quit', r)
95
+ *
96
+ * }
97
+ * test()
98
+ * .catch((err) => {
99
+ * console.log(err)
100
+ * })
101
+ *
102
+ */
103
+ async function ls(fdRemote = '.') {
104
+ return null
105
+ }
106
+
107
+
108
+ /**
109
+ * 關閉與伺服器連線
110
+ *
111
+ * @return {Promise} 回傳Promise,resolve回傳成功訊息,reject回傳錯誤訊息
112
+ * @example
113
+ * import WFtp from './src/WFtp.mjs'
114
+ *
115
+ * async function test() {
116
+ * let r
117
+ *
118
+ * let ftp = WFtp()
119
+ * // console.log('ftp', ftp)
120
+ *
121
+ * await ftp.conn({
122
+ * hostname: st.up.hostname,
123
+ * port: st.up.port,
124
+ * username: st.up.username,
125
+ * password: st.up.password,
126
+ * })
127
+ *
128
+ * //actions
129
+ *
130
+ * r = await ftp.quit()
131
+ * console.log('ftp.quit', r)
132
+ *
133
+ * }
134
+ * test()
135
+ * .catch((err) => {
136
+ * console.log(err)
137
+ * })
138
+ */
139
+ async function quit() {
140
+ return null
141
+ }
142
+
143
+
144
+ /**
145
+ * 取得伺服器指定檔案資訊
146
+ *
147
+ * @param {String} opt.fpRemote 輸入伺服器上指定檔案字串
148
+ * @return {Promise} 回傳Promise,resolve回傳檔案資訊,reject回傳錯誤訊息
149
+ * @example
150
+ * import WFtp from './src/WFtp.mjs'
151
+ *
152
+ * async function test() {
153
+ * let r
154
+ *
155
+ * let ftp = WFtp()
156
+ * // console.log('ftp', ftp)
157
+ *
158
+ * await ftp.conn({
159
+ * hostname: st.up.hostname,
160
+ * port: st.up.port,
161
+ * username: st.up.username,
162
+ * password: st.up.password,
163
+ * })
164
+ *
165
+ * r = await ftp.stateFile('./_test_upload_client/DECL_20210805055044.csv')
166
+ * console.log('ftp.stateFile', r)
167
+ *
168
+ * r = await ftp.quit()
169
+ * console.log('ftp.quit', r)
170
+ *
171
+ * }
172
+ * test()
173
+ * .catch((err) => {
174
+ * console.log(err)
175
+ * })
176
+ */
177
+ async function stateFile(fpRemote) {
178
+ return null
179
+ }
180
+
181
+
182
+ /**
183
+ * 確認伺服器指定檔案是否存在
184
+ *
185
+ * @param {String} opt.fpRemote 輸入伺服器上指定檔案字串
186
+ * @return {Promise} 回傳Promise,resolve回傳指定檔案是否存在布林值,reject回傳錯誤訊息
187
+ * @example
188
+ * import WFtp from './src/WFtp.mjs'
189
+ *
190
+ * async function test() {
191
+ * let r
192
+ *
193
+ * let ftp = WFtp()
194
+ * // console.log('ftp', ftp)
195
+ *
196
+ * await ftp.conn({
197
+ * hostname: st.up.hostname,
198
+ * port: st.up.port,
199
+ * username: st.up.username,
200
+ * password: st.up.password,
201
+ * })
202
+ *
203
+ * r = await ftp.isFile('./_test_upload_client/DECL_20210805055044.csv')
204
+ * console.log('ftp.isFile', r)
205
+ *
206
+ * r = await ftp.quit()
207
+ * console.log('ftp.quit', r)
208
+ *
209
+ * }
210
+ * test()
211
+ * .catch((err) => {
212
+ * console.log(err)
213
+ * })
214
+ */
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) {
254
+ return null
255
+ }
256
+
257
+
258
+ /**
259
+ * 下載伺服器指定檔案至本機
260
+ *
261
+ * @param {String} opt.fpRemote 輸入伺服器上指定檔案字串
262
+ * @param {String} opt.fpLocal 輸入本機指定檔案字串
263
+ * @param {Function} [opt.cbProcess=null] 輸入回調進度函數
264
+ * @return {Promise} 回傳Promise,resolve回傳成功訊息,reject回傳錯誤訊息
265
+ * @example
266
+ * import WFtp from './src/WFtp.mjs'
267
+ *
268
+ * async function test() {
269
+ * let r
270
+ *
271
+ * let ftp = WFtp()
272
+ * // console.log('ftp', ftp)
273
+ *
274
+ * await ftp.conn({
275
+ * hostname: st.up.hostname,
276
+ * port: st.up.port,
277
+ * username: st.up.username,
278
+ * password: st.up.password,
279
+ * })
280
+ *
281
+ * r = await ftp.download('./DECL_20210805055044.csv', './_test_download_client/DECL_20210805055044.csv', (p) => {
282
+ * console.log('ftp.download p', p.name, p.progress)
283
+ * })
284
+ * console.log('ftp.download', r)
285
+ *
286
+ * r = await ftp.quit()
287
+ * console.log('ftp.quit', r)
288
+ *
289
+ * }
290
+ * test()
291
+ * .catch((err) => {
292
+ * console.log(err)
293
+ * })
294
+ */
295
+ async function download(fpRemote, fpLocal, cbProcess = null) {
296
+ return null
297
+ }
298
+
299
+
300
+ /**
301
+ * 上傳本機指定檔案至伺服器
302
+ *
303
+ * @param {String} opt.fpLocal 輸入本機指定檔案字串
304
+ * @param {String} opt.fpRemote 輸入伺服器上指定檔案字串
305
+ * @param {Function} [opt.cbProcess=null] 輸入回調進度函數
306
+ * @return {Promise} 回傳Promise,resolve回傳成功訊息,reject回傳錯誤訊息
307
+ * @example
308
+ * import WFtp from './src/WFtp.mjs'
309
+ *
310
+ * async function test() {
311
+ * let r
312
+ *
313
+ * let ftp = WFtp()
314
+ * // console.log('ftp', ftp)
315
+ *
316
+ * await ftp.conn({
317
+ * hostname: st.up.hostname,
318
+ * port: st.up.port,
319
+ * username: st.up.username,
320
+ * password: st.up.password,
321
+ * })
322
+ *
323
+ * r = await ftp.upload('./_test_upload_client/DECL_20210805055044.csv', './DECL_20210805055044.csv', (p) => {
324
+ * console.log('ftp.upload p', p.name, p.progress)
325
+ * })
326
+ * console.log('ftp.upload', r)
327
+ *
328
+ * r = await ftp.quit()
329
+ * console.log('ftp.quit', r)
330
+ *
331
+ * }
332
+ * test()
333
+ * .catch((err) => {
334
+ * console.log(err)
335
+ * })
336
+ */
337
+ async function upload(fpLocal, fpRemote, cbProcess) {
338
+ return null
339
+ }
340
+
341
+
342
+ /**
343
+ * 同步伺服器上指定資料夾內檔案至本機
344
+ *
345
+ * @param {String} opt.fdRemote 輸入伺服器上指定資料夾字串
346
+ * @param {String} opt.fdLocal 輸入本機指定資料夾字串
347
+ * @param {Function} [opt.cbProcess=null] 輸入回調進度函數
348
+ * @return {Promise} 回傳Promise,resolve回傳成功訊息,reject回傳錯誤訊息
349
+ * @example
350
+ * import WFtp from './src/WFtp.mjs'
351
+ *
352
+ * async function test() {
353
+ * let r
354
+ *
355
+ * let ftp = WFtp()
356
+ * // console.log('ftp', ftp)
357
+ *
358
+ * await ftp.conn({
359
+ * hostname: st.up.hostname,
360
+ * port: st.up.port,
361
+ * username: st.up.username,
362
+ * password: st.up.password,
363
+ * })
364
+ *
365
+ * r = await ftp.syncToLocal('.', './_test_download_client', (p) => {
366
+ * console.log('ftp.syncToLocal p', p.name, p.progress)
367
+ * })
368
+ * console.log('ftp.syncToLocal', r)
369
+ *
370
+ * r = await ftp.quit()
371
+ * console.log('ftp.quit', r)
372
+ *
373
+ * }
374
+ * test()
375
+ * .catch((err) => {
376
+ * console.log(err)
377
+ * })
378
+ */
379
+ async function syncToLocal(fdRemote, fdLocal, cbProcess) {
380
+ return null
381
+ }
382
+
383
+
384
+ /**
385
+ * 同步本機指定資料夾內檔案至伺服器
386
+ *
387
+ * @param {String} opt.fdLocal 輸入本機指定資料夾字串
388
+ * @param {String} opt.fdRemote 輸入伺服器上指定資料夾字串
389
+ * @param {Function} [opt.cbProcess=null] 輸入回調進度函數
390
+ * @return {Promise} 回傳Promise,resolve回傳成功訊息,reject回傳錯誤訊息
391
+ * @example
392
+ * import WFtp from './src/WFtp.mjs'
393
+ *
394
+ * async function test() {
395
+ * let r
396
+ *
397
+ * let ftp = WFtp()
398
+ * // console.log('ftp', ftp)
399
+ *
400
+ * await ftp.conn({
401
+ * hostname: st.up.hostname,
402
+ * port: st.up.port,
403
+ * username: st.up.username,
404
+ * password: st.up.password,
405
+ * })
406
+ *
407
+ * r = await ftp.syncToRemote('./_test_upload_client', '.', (p) => {
408
+ * console.log('ftp.syncToRemote p', p.name, p.progress)
409
+ * })
410
+ * console.log('ftp.syncToRemote', r)
411
+ *
412
+ * r = await ftp.quit()
413
+ * console.log('ftp.quit', r)
414
+ *
415
+ * }
416
+ * test()
417
+ * .catch((err) => {
418
+ * console.log(err)
419
+ * })
420
+ */
421
+ async function syncToRemote(fdLocal, fdRemote, cbProcess) {
422
+ return null
423
+ }
424
+
425
+
426
+ /**
427
+ * 操作FTP,包含連線、下載、資料夾內檔案同步下載、上傳、資料夾內檔案同步上傳等功能
428
+ *
429
+ * @returns {Object} 回傳FTP操作物件,包含conn、ls、stateFile、isFile、download、syncToLocal、syncToRemote、upload、quit。
430
+ * @example
431
+ * import WFtp from './src/WFtp.mjs'
432
+ *
433
+ * async function test_dw() {
434
+ * let r
435
+ *
436
+ * let ftp = WFtp()
437
+ * // console.log('ftp', ftp)
438
+ *
439
+ * await ftp.conn({
440
+ * hostname: `{hostname}`,
441
+ * port: `{port}`,
442
+ * username: `{username}`,
443
+ * password: `{password}`,
444
+ * })
445
+ *
446
+ * async function core() {
447
+ *
448
+ * let fps = await ftp.ls('.')
449
+ * console.log('ftp.ls', fps[0], fps.length)
450
+ *
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
+ * })
466
+ *
467
+ * r = await ftp.quit()
468
+ * console.log('ftp.quit', r)
469
+ *
470
+ * }
471
+ * test_dw()
472
+ * .catch((err) => {
473
+ * console.log(err)
474
+ * })
475
+ * // ftp.ls {
476
+ * // name: 'DECL_202108.csv',
477
+ * // type: 0,
478
+ * // time: 1658302140000,
479
+ * // size: '218690',
480
+ * // owner: 'ftp',
481
+ * // group: 'ftp',
482
+ * // userPermissions: { read: true, write: true, exec: false },
483
+ * // groupPermissions: { read: true, write: true, exec: false },
484
+ * // otherPermissions: { read: true, write: true, exec: false }
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: [] }
510
+ * // ftp.quit { code: 221, text: '221 Goodbye.', isMark: false, isError: false }
511
+ *
512
+ * async function test_up() {
513
+ * let r
514
+ *
515
+ * let ftp = WFtp()
516
+ * // console.log('ftp', ftp)
517
+ *
518
+ * await ftp.conn({
519
+ * hostname: `{hostname}`,
520
+ * port: `{port}`,
521
+ * username: `{username}`,
522
+ * password: `{password}`,
523
+ * })
524
+ *
525
+ * async function core() {
526
+ *
527
+ * let fps = await ftp.ls('.')
528
+ * console.log('ftp.ls', fps[0], fps.length)
529
+ *
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
+ * })
545
+ *
546
+ * r = await ftp.quit()
547
+ * console.log('ftp.quit', r)
548
+ *
549
+ * }
550
+ * test_up()
551
+ * .catch((err) => {
552
+ * console.log(err)
553
+ * })
554
+ * // ftp.ls {
555
+ * // name: 'DECL_202108.csv',
556
+ * // type: 0,
557
+ * // time: 1658366760000,
558
+ * // size: '218690',
559
+ * // owner: 'ftp',
560
+ * // group: 'ftp',
561
+ * // userPermissions: { read: true, write: true, exec: false },
562
+ * // groupPermissions: { read: true, write: true, exec: false },
563
+ * // otherPermissions: { read: true, write: true, exec: false }
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: [] }
569
+ * // ftp.quit { code: 221, text: '221 Goodbye.', isMark: false, isError: false }
570
+ *
571
+ */
71
572
  function WFtp() {
573
+ let doc = {
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,
584
+ }
72
585
 
73
586
  function WFtpCore() {
74
587
  let Ftp = null
@@ -110,11 +623,12 @@ function WFtp() {
110
623
 
111
624
  try {
112
625
  Ftp = new Jsftp({
113
- host: hostname,
626
+ host: hostname, //hostname or ip
114
627
  port, // defaults to 21
115
628
  user: username, // defaults to "anonymous"
116
629
  pass: password, // defaults to "@anonymous"
117
630
  })
631
+ Ftp.__doc__ = doc
118
632
  pm.resolve('ok')
119
633
  }
120
634
  catch (err) {
@@ -125,7 +639,7 @@ function WFtp() {
125
639
  }
126
640
 
127
641
 
128
- async function ftpLs(remoteFd = '.') {
642
+ async function ftpLs(fdRemote = '.') {
129
643
 
130
644
  //pm
131
645
  let pm = genPm()
@@ -136,11 +650,17 @@ function WFtp() {
136
650
  return pm
137
651
  }
138
652
 
139
- Ftp.ls(remoteFd, (err, res) => {
653
+ Ftp.ls(fdRemote, (err, res) => {
140
654
  if (err) {
141
655
  pm.reject(err)
142
656
  }
143
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
+ })
144
664
  pm.resolve(res)
145
665
  }
146
666
  })
@@ -193,19 +713,62 @@ function WFtp() {
193
713
  }
194
714
 
195
715
 
196
- 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) {
197
751
 
198
752
  //ftpStateFile
199
753
  let file = await ftpStateFile(fpRemote)
200
754
 
201
- //b
202
- 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)
203
766
 
204
767
  return b
205
768
  }
206
769
 
207
770
 
208
- async function ftpDownload(fpRemote, fpLocal, cbProcess) {
771
+ async function ftpDownload(fpRemote, fpLocal, cbProcess = null) {
209
772
 
210
773
  //pm
211
774
  let pm = genPm()
@@ -240,6 +803,22 @@ function WFtp() {
240
803
  let file = await ftpStateFile(fpRemote)
241
804
  // console.log('file', file)
242
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
+
243
822
  //fileSize
244
823
  let fileSize = get(file, 'size')
245
824
 
@@ -403,11 +982,9 @@ function WFtp() {
403
982
 
404
983
  //ftpLs
405
984
  let fsRemote = await ftpLs(fdRemote)
406
- // fsRemote = map(fsRemote, (v) => {
407
- // let d = dayjs(v.time)
408
- // v.stat = d.format('YYYY-MM-DDTHH:mm:ss')
409
- // return v
410
- // })
985
+ fsRemote = filter(fsRemote, (v) => {
986
+ return !v.isFolder
987
+ })
411
988
  // console.log('fsRemote', fsRemote)
412
989
 
413
990
  //check fdLocal
@@ -580,7 +1157,8 @@ function WFtp() {
580
1157
  conn: ftpConn,
581
1158
  ls: ftpLs,
582
1159
  stateFile: ftpStateFile,
583
- checkFile: ftpCheckFile,
1160
+ isFile: ftpIsFile,
1161
+ isFolder: ftpIsFolder,
584
1162
  download: ftpDownload,
585
1163
  syncToLocal: ftpSyncToLocal,
586
1164
  syncToRemote: ftpSyncToRemote,