w-ftp 1.0.2 → 1.0.5
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/README.md +50 -33
- package/dist/w-ftp.umd.js +2 -2
- package/dist/w-ftp.umd.js.map +1 -1
- package/docs/WFtp.mjs.html +280 -91
- package/docs/global.html +345 -182
- package/docs/index.html +2 -2
- package/docs/jsftp.js.html +7 -3
- package/g-download.mjs +27 -10
- package/g-upload.mjs +27 -11
- package/package.json +10 -3
- package/src/WFtp.mjs +278 -89
- package/src/jsftp.js +5 -1
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
|
|
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
|
|
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
|
|
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
|
|
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.
|
|
203
|
-
* console.log('ftp.
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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、
|
|
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
|
|
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
|
-
*
|
|
408
|
-
* console.log('ftp.ls', fps[0], fps.length)
|
|
446
|
+
* async function core() {
|
|
409
447
|
*
|
|
410
|
-
*
|
|
411
|
-
* console.log('ftp.
|
|
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
|
-
*
|
|
416
|
-
*
|
|
417
|
-
*
|
|
418
|
-
*
|
|
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
|
-
*
|
|
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:
|
|
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
|
-
* // }
|
|
439
|
-
* // ftp.
|
|
440
|
-
* //
|
|
441
|
-
* // ftp.
|
|
442
|
-
* // ftp.
|
|
443
|
-
* // ftp.
|
|
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
|
|
512
|
+
* async function test_up() {
|
|
447
513
|
* let r
|
|
448
514
|
*
|
|
449
515
|
* let ftp = WFtp()
|
|
@@ -456,81 +522,70 @@ async function ftpSyncToRemote(fdLocal, fdRemote, cbProcess) {
|
|
|
456
522
|
* password: `{password}`,
|
|
457
523
|
* })
|
|
458
524
|
*
|
|
459
|
-
*
|
|
460
|
-
* console.log('ftp.ls', fps[0], fps.length)
|
|
525
|
+
* async function core() {
|
|
461
526
|
*
|
|
462
|
-
*
|
|
463
|
-
* console.log('ftp.
|
|
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
|
-
*
|
|
468
|
-
*
|
|
469
|
-
*
|
|
470
|
-
*
|
|
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
|
-
*
|
|
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:
|
|
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
|
-
* // }
|
|
491
|
-
* // ftp.
|
|
492
|
-
* // ftp.
|
|
493
|
-
* // ftp.
|
|
494
|
-
* // ftp.
|
|
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
|
-
let
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
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,
|
|
530
584
|
}
|
|
531
585
|
|
|
532
586
|
function WFtpCore() {
|
|
533
587
|
let Ftp = null
|
|
588
|
+
let timeLimit = 1 * 60 * 1000 //1hr
|
|
534
589
|
|
|
535
590
|
|
|
536
591
|
async function ftpConn(opt = {}) {
|
|
@@ -567,6 +622,18 @@ function WFtp() {
|
|
|
567
622
|
return pm
|
|
568
623
|
}
|
|
569
624
|
|
|
625
|
+
//timeLimit
|
|
626
|
+
let _timeLimit = get(opt, 'timeLimit')
|
|
627
|
+
if (isnum(_timeLimit)) {
|
|
628
|
+
|
|
629
|
+
//cint
|
|
630
|
+
_timeLimit = cint(_timeLimit)
|
|
631
|
+
|
|
632
|
+
//update
|
|
633
|
+
timeLimit = _timeLimit
|
|
634
|
+
|
|
635
|
+
}
|
|
636
|
+
|
|
570
637
|
try {
|
|
571
638
|
Ftp = new Jsftp({
|
|
572
639
|
host: hostname, //hostname or ip
|
|
@@ -574,6 +641,7 @@ function WFtp() {
|
|
|
574
641
|
user: username, // defaults to "anonymous"
|
|
575
642
|
pass: password, // defaults to "@anonymous"
|
|
576
643
|
})
|
|
644
|
+
Ftp.__doc__ = doc
|
|
577
645
|
pm.resolve('ok')
|
|
578
646
|
}
|
|
579
647
|
catch (err) {
|
|
@@ -595,11 +663,26 @@ function WFtp() {
|
|
|
595
663
|
return pm
|
|
596
664
|
}
|
|
597
665
|
|
|
666
|
+
//timeLimit
|
|
667
|
+
let t = setTimeout(() => {
|
|
668
|
+
pm.reject(`timeout[${timeLimit}]`)
|
|
669
|
+
}, timeLimit)
|
|
670
|
+
|
|
598
671
|
Ftp.ls(fdRemote, (err, res) => {
|
|
672
|
+
|
|
673
|
+
//clearTimeout
|
|
674
|
+
clearTimeout(t)
|
|
675
|
+
|
|
599
676
|
if (err) {
|
|
600
677
|
pm.reject(err)
|
|
601
678
|
}
|
|
602
679
|
else {
|
|
680
|
+
res = map(res, (v) => {
|
|
681
|
+
let d = ot(v.time) //jsfpt解析時間係基於ls, 其檔案變更時間精度只至分而沒有秒, 故無法提供精確的檔案變更時間
|
|
682
|
+
v.ctime = d.format('YYYY-MM-DDTHH:mm:ssZ') //添加UTC時間
|
|
683
|
+
v.isFolder = ftpIsFolderCore(v)
|
|
684
|
+
return v
|
|
685
|
+
})
|
|
603
686
|
pm.resolve(res)
|
|
604
687
|
}
|
|
605
688
|
})
|
|
@@ -619,7 +702,29 @@ function WFtp() {
|
|
|
619
702
|
return pm
|
|
620
703
|
}
|
|
621
704
|
|
|
705
|
+
//timeLimit
|
|
706
|
+
let t = setTimeout(() => {
|
|
707
|
+
|
|
708
|
+
//destroy
|
|
709
|
+
Ftp.destroy()
|
|
710
|
+
|
|
711
|
+
//clear
|
|
712
|
+
Ftp = null
|
|
713
|
+
|
|
714
|
+
pm.reject(`timeout[${timeLimit}]`)
|
|
715
|
+
}, timeLimit)
|
|
716
|
+
|
|
622
717
|
Ftp.raw('quit', (err, res) => {
|
|
718
|
+
|
|
719
|
+
//clearTimeout
|
|
720
|
+
clearTimeout(t)
|
|
721
|
+
|
|
722
|
+
//destroy
|
|
723
|
+
Ftp.destroy()
|
|
724
|
+
|
|
725
|
+
//clear
|
|
726
|
+
Ftp = null
|
|
727
|
+
|
|
623
728
|
if (err) {
|
|
624
729
|
pm.reject(err)
|
|
625
730
|
}
|
|
@@ -652,13 +757,56 @@ function WFtp() {
|
|
|
652
757
|
}
|
|
653
758
|
|
|
654
759
|
|
|
655
|
-
|
|
760
|
+
function ftpIsFolderCore(file) {
|
|
761
|
+
|
|
762
|
+
//check
|
|
763
|
+
if (!iseobj(file)) {
|
|
764
|
+
return false
|
|
765
|
+
}
|
|
766
|
+
|
|
767
|
+
//type
|
|
768
|
+
let type = get(file, 'type', -1)
|
|
769
|
+
|
|
770
|
+
//b
|
|
771
|
+
let b = type === 1
|
|
772
|
+
|
|
773
|
+
return b
|
|
774
|
+
}
|
|
775
|
+
|
|
776
|
+
|
|
777
|
+
function ftpIsFileCore(file) {
|
|
778
|
+
|
|
779
|
+
//check
|
|
780
|
+
if (!iseobj(file)) {
|
|
781
|
+
return false
|
|
782
|
+
}
|
|
783
|
+
|
|
784
|
+
//type
|
|
785
|
+
let type = get(file, 'type', -1)
|
|
786
|
+
|
|
787
|
+
//b
|
|
788
|
+
let b = type === 0
|
|
789
|
+
|
|
790
|
+
return b
|
|
791
|
+
}
|
|
792
|
+
|
|
793
|
+
|
|
794
|
+
async function ftpIsFolder(fpRemote) {
|
|
656
795
|
|
|
657
796
|
//ftpStateFile
|
|
658
797
|
let file = await ftpStateFile(fpRemote)
|
|
659
798
|
|
|
660
|
-
//
|
|
661
|
-
let b =
|
|
799
|
+
//ftpIsFolderCore
|
|
800
|
+
let b = ftpIsFolderCore(file)
|
|
801
|
+
|
|
802
|
+
return b
|
|
803
|
+
}
|
|
804
|
+
|
|
805
|
+
|
|
806
|
+
async function ftpIsFile(fpRemote) {
|
|
807
|
+
|
|
808
|
+
//ftpIsFileCore
|
|
809
|
+
let b = await ftpIsFileCore(fpRemote)
|
|
662
810
|
|
|
663
811
|
return b
|
|
664
812
|
}
|
|
@@ -699,6 +847,22 @@ function WFtp() {
|
|
|
699
847
|
let file = await ftpStateFile(fpRemote)
|
|
700
848
|
// console.log('file', file)
|
|
701
849
|
|
|
850
|
+
//ftpIsFileCore
|
|
851
|
+
let b = await ftpIsFileCore(file)
|
|
852
|
+
// console.log('b', b)
|
|
853
|
+
|
|
854
|
+
//check
|
|
855
|
+
if (!b) {
|
|
856
|
+
pm.reject(`fpRemote[${fpRemote}] is not a file`)
|
|
857
|
+
return pm
|
|
858
|
+
}
|
|
859
|
+
|
|
860
|
+
//check
|
|
861
|
+
if (!iseobj(file)) {
|
|
862
|
+
pm.reject(`fpRemote[${fpRemote}] does not have information`)
|
|
863
|
+
return pm
|
|
864
|
+
}
|
|
865
|
+
|
|
702
866
|
//fileSize
|
|
703
867
|
let fileSize = get(file, 'size')
|
|
704
868
|
|
|
@@ -710,10 +874,19 @@ function WFtp() {
|
|
|
710
874
|
fileSize = cint(fileSize)
|
|
711
875
|
// console.log('fileSize', fileSize)
|
|
712
876
|
|
|
877
|
+
//timeLimit
|
|
878
|
+
let t = setTimeout(() => {
|
|
879
|
+
pm.reject(`timeout[${timeLimit}]`)
|
|
880
|
+
}, timeLimit)
|
|
881
|
+
|
|
713
882
|
Ftp.get(fpRemote, (err, socket) => {
|
|
714
883
|
|
|
715
884
|
//check
|
|
716
885
|
if (err) {
|
|
886
|
+
|
|
887
|
+
//clearTimeout
|
|
888
|
+
clearTimeout(t)
|
|
889
|
+
|
|
717
890
|
pm.reject(err)
|
|
718
891
|
}
|
|
719
892
|
|
|
@@ -751,6 +924,10 @@ function WFtp() {
|
|
|
751
924
|
|
|
752
925
|
//on close
|
|
753
926
|
socket.on('close', (err) => {
|
|
927
|
+
|
|
928
|
+
//clearTimeout
|
|
929
|
+
clearTimeout(t)
|
|
930
|
+
|
|
754
931
|
if (err) {
|
|
755
932
|
pm.reject(err)
|
|
756
933
|
}
|
|
@@ -817,18 +994,31 @@ function WFtp() {
|
|
|
817
994
|
// //createReadStream
|
|
818
995
|
// let reader = fs.createReadStream(fpLocal)
|
|
819
996
|
|
|
997
|
+
//timeLimit
|
|
998
|
+
let t = setTimeout(() => {
|
|
999
|
+
pm.reject(`timeout[${timeLimit}]`)
|
|
1000
|
+
}, timeLimit)
|
|
1001
|
+
|
|
820
1002
|
let dss = 0
|
|
821
1003
|
Ftp.put(bufferLocal, fpRemote, (err, buffer) => {
|
|
822
1004
|
// console.log('Ftp.put', err, buffer)
|
|
823
1005
|
|
|
824
1006
|
//check
|
|
825
1007
|
if (err) {
|
|
1008
|
+
|
|
1009
|
+
//clearTimeout
|
|
1010
|
+
clearTimeout(t)
|
|
1011
|
+
|
|
826
1012
|
pm.reject(err)
|
|
827
1013
|
return
|
|
828
1014
|
}
|
|
829
1015
|
|
|
830
1016
|
//check
|
|
831
1017
|
if (size(buffer) === 0) {
|
|
1018
|
+
|
|
1019
|
+
//clearTimeout
|
|
1020
|
+
clearTimeout(t)
|
|
1021
|
+
|
|
832
1022
|
pm.resolve('ok')
|
|
833
1023
|
return
|
|
834
1024
|
}
|
|
@@ -862,11 +1052,9 @@ function WFtp() {
|
|
|
862
1052
|
|
|
863
1053
|
//ftpLs
|
|
864
1054
|
let fsRemote = await ftpLs(fdRemote)
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
// return v
|
|
869
|
-
// })
|
|
1055
|
+
fsRemote = filter(fsRemote, (v) => {
|
|
1056
|
+
return !v.isFolder
|
|
1057
|
+
})
|
|
870
1058
|
// console.log('fsRemote', fsRemote)
|
|
871
1059
|
|
|
872
1060
|
//check fdLocal
|
|
@@ -1039,7 +1227,8 @@ function WFtp() {
|
|
|
1039
1227
|
conn: ftpConn,
|
|
1040
1228
|
ls: ftpLs,
|
|
1041
1229
|
stateFile: ftpStateFile,
|
|
1042
|
-
|
|
1230
|
+
isFile: ftpIsFile,
|
|
1231
|
+
isFolder: ftpIsFolder,
|
|
1043
1232
|
download: ftpDownload,
|
|
1044
1233
|
syncToLocal: ftpSyncToLocal,
|
|
1045
1234
|
syncToRemote: ftpSyncToRemote,
|
package/src/jsftp.js
CHANGED
|
@@ -582,7 +582,7 @@ Ftp.prototype.put = function(from, destination, callback) {
|
|
|
582
582
|
// })
|
|
583
583
|
|
|
584
584
|
socket.on('drain', () => {
|
|
585
|
-
console.log('drain')
|
|
585
|
+
// console.log('drain')
|
|
586
586
|
if (from.length > pointer + SLICE) {
|
|
587
587
|
newBuf = from.slice(pointer, pointer + SLICE)
|
|
588
588
|
pointer += SLICE
|
|
@@ -767,11 +767,14 @@ Ftp.prototype.getPasvSocket = function(callback = NOOP) {
|
|
|
767
767
|
*/
|
|
768
768
|
Ftp.prototype.ls = function(filePath, callback) {
|
|
769
769
|
function entriesToList(err, entries) {
|
|
770
|
+
// console.log('entriesToList', err, entries)
|
|
770
771
|
if (err) {
|
|
771
772
|
return callback(err)
|
|
772
773
|
}
|
|
773
774
|
|
|
775
|
+
//ListingParser.parseFtpEntries是基於parse-listing解析, 但原始數據是ls而來, 本身就沒有到秒, 故只有類似dir提供的粗略時間, 無法像fs.statSync提供精確的產生與最新變更時間
|
|
774
776
|
ListingParser.parseFtpEntries(entries.text || entries, (err, files) => {
|
|
777
|
+
// console.log('ListingParser.parseFtpEntries', err, files)
|
|
775
778
|
if (err) {
|
|
776
779
|
return callback(err)
|
|
777
780
|
}
|
|
@@ -790,6 +793,7 @@ Ftp.prototype.ls = function(filePath, callback) {
|
|
|
790
793
|
}
|
|
791
794
|
else {
|
|
792
795
|
this.raw('stat', filePath, (err, data) => {
|
|
796
|
+
// console.log('filePath', filePath, data)
|
|
793
797
|
// We might be connected to a server that doesn't support the
|
|
794
798
|
// 'STAT' command, which is set as default. We use 'LIST' instead,
|
|
795
799
|
// and we set the variable `useList` to true, to avoid extra round
|