w-ftp 1.0.0 → 1.0.3

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.
@@ -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#WFtp">WFtp</a></li></ul>
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>
31
31
  </nav>
32
32
 
33
33
  <div id="main">
@@ -64,55 +64,513 @@ import fsTreeFolder from 'wsemi/src/fsTreeFolder.mjs'
64
64
  import fsIsFolder from 'wsemi/src/fsIsFolder.mjs'
65
65
  import fsIsFile from 'wsemi/src/fsIsFile.mjs'
66
66
  import fsCreateFolder from 'wsemi/src/fsCreateFolder.mjs'
67
- // import Jsftp from 'jsftp'
68
67
  import Jsftp from './jsftp.js'
69
- console.log('Jsftp', Jsftp)
70
68
 
71
69
 
72
70
  /**
73
- * 指定FTP伺服器資料夾內檔案並自動同步至本機,只能用於Windows作業系統
71
+ * 連線至FPT伺服器
74
72
  *
75
- * @param {String} fp 輸入檔案路徑字串
76
73
  * @param {Object} [opt={}] 輸入設定物件,預設{}
77
- * @param {String} [opt.ver='4.8'] 輸入調用windows程序之Net Framework版本字串,可有'4.5'、'4.6'、'4.7.2'與'4.8',預設'4.8'
78
- * @returns {Promise} 回傳Promise,resolve回傳成功訊息,reject回傳錯誤訊息
74
+ * @param {String} opt.hostname='' 輸入hostname字串
75
+ * @param {Number} opt.port='' 輸入port正整數
76
+ * @param {String} opt.username='' 輸入帳號字串
77
+ * @param {String} opt.password='' 輸入密碼字串
78
+ * @return {Promise} 回傳Promise,resolve回傳成功訊息,reject回傳錯誤訊息
79
79
  * @example
80
80
  * import WFtp from './src/WFtp.mjs'
81
81
  *
82
82
  * async function test() {
83
+ * let r
83
84
  *
84
- * //fp
85
- * let fp = './g.mseed'
86
- *
87
- * //WFtp
88
- * let r = await WFtp(fp)
89
- * console.log(r)
90
- * // [
91
- * // {
92
- * // name: 'SE.RST01.00.HNE.D.2020-09-17T013552.000000.csv',
93
- * // path: null,
94
- * // data: { heads: [Object], records: [Array] }
95
- * // },
96
- * // {
97
- * // name: 'SE.RST01.00.HNN.D.2020-09-17T013552.000000.csv',
98
- * // path: null,
99
- * // data: { heads: [Object], records: [Array] }
100
- * // },
101
- * // {
102
- * // name: 'SE.RST01.00.HNZ.D.2020-09-17T013552.000000.csv',
103
- * // path: null,
104
- * // data: { heads: [Object], records: [Array] }
105
- * // }
106
- * // ]
85
+ * let ftp = WFtp()
86
+ * // console.log('ftp', ftp)
87
+ *
88
+ * await ftp.conn({
89
+ * hostname: st.up.hostname,
90
+ * port: st.up.port,
91
+ * username: st.up.username,
92
+ * password: st.up.password,
93
+ * })
94
+ *
95
+ * //actions
96
+ *
97
+ * r = await ftp.quit()
98
+ * console.log('ftp.quit', r)
99
+ *
100
+ * }
101
+ * test()
102
+ * .catch((err) => {
103
+ * console.log(err)
104
+ * })
105
+ *
106
+ */
107
+ async function ftpConn(opt = {}) {
108
+ return null
109
+ }
110
+
111
+
112
+ /**
113
+ * 遍歷伺服器上指定資料夾內檔案清單資訊
114
+ *
115
+ * @param {String} opt.fdRemote 輸入伺服器上指定資料夾字串
116
+ * @return {Promise} 回傳Promise,resolve回傳檔案清單資訊,reject回傳錯誤訊息
117
+ * @example
118
+ * import WFtp from './src/WFtp.mjs'
119
+ *
120
+ * async function test() {
121
+ * let r
122
+ *
123
+ * let ftp = WFtp()
124
+ * // console.log('ftp', ftp)
125
+ *
126
+ * await ftp.conn({
127
+ * hostname: st.up.hostname,
128
+ * port: st.up.port,
129
+ * username: st.up.username,
130
+ * password: st.up.password,
131
+ * })
132
+ *
133
+ * let fps = await ftp.ls('.')
134
+ * console.log('ftp.ls', fps[0], fps.length)
135
+ *
136
+ * r = await ftp.quit()
137
+ * console.log('ftp.quit', r)
138
+ *
139
+ * }
140
+ * test()
141
+ * .catch((err) => {
142
+ * console.log(err)
143
+ * })
144
+ *
145
+ */
146
+ async function ftpLs(fdRemote = '.') {
147
+ return null
148
+ }
149
+
150
+
151
+ /**
152
+ * 關閉與伺服器連線
153
+ *
154
+ * @return {Promise} 回傳Promise,resolve回傳成功訊息,reject回傳錯誤訊息
155
+ * @example
156
+ * import WFtp from './src/WFtp.mjs'
157
+ *
158
+ * async function test() {
159
+ * let r
160
+ *
161
+ * let ftp = WFtp()
162
+ * // console.log('ftp', ftp)
163
+ *
164
+ * await ftp.conn({
165
+ * hostname: st.up.hostname,
166
+ * port: st.up.port,
167
+ * username: st.up.username,
168
+ * password: st.up.password,
169
+ * })
170
+ *
171
+ * //actions
172
+ *
173
+ * r = await ftp.quit()
174
+ * console.log('ftp.quit', r)
175
+ *
176
+ * }
177
+ * test()
178
+ * .catch((err) => {
179
+ * console.log(err)
180
+ * })
181
+ */
182
+ async function ftpQuit() {
183
+ return null
184
+ }
185
+
186
+
187
+ /**
188
+ * 取得伺服器指定檔案資訊
189
+ *
190
+ * @param {String} opt.fpRemote 輸入伺服器上指定檔案字串
191
+ * @return {Promise} 回傳Promise,resolve回傳檔案資訊,reject回傳錯誤訊息
192
+ * @example
193
+ * import WFtp from './src/WFtp.mjs'
194
+ *
195
+ * async function test() {
196
+ * let r
197
+ *
198
+ * let ftp = WFtp()
199
+ * // console.log('ftp', ftp)
200
+ *
201
+ * await ftp.conn({
202
+ * hostname: st.up.hostname,
203
+ * port: st.up.port,
204
+ * username: st.up.username,
205
+ * password: st.up.password,
206
+ * })
207
+ *
208
+ * r = await ftp.stateFile('./_test_upload_client/DECL_20210805055044.csv')
209
+ * console.log('ftp.stateFile', r)
210
+ *
211
+ * r = await ftp.quit()
212
+ * console.log('ftp.quit', r)
107
213
  *
108
214
  * }
109
215
  * test()
110
216
  * .catch((err) => {
111
- * console.log('catch', err)
217
+ * console.log(err)
218
+ * })
219
+ */
220
+ async function ftpStateFile(fpRemote) {
221
+ return null
222
+ }
223
+
224
+
225
+ /**
226
+ * 確認伺服器指定檔案是否存在
227
+ *
228
+ * @param {String} opt.fpRemote 輸入伺服器上指定檔案字串
229
+ * @return {Promise} 回傳Promise,resolve回傳指定檔案是否存在布林值,reject回傳錯誤訊息
230
+ * @example
231
+ * import WFtp from './src/WFtp.mjs'
232
+ *
233
+ * async function test() {
234
+ * let r
235
+ *
236
+ * let ftp = WFtp()
237
+ * // console.log('ftp', ftp)
238
+ *
239
+ * await ftp.conn({
240
+ * hostname: st.up.hostname,
241
+ * port: st.up.port,
242
+ * username: st.up.username,
243
+ * password: st.up.password,
112
244
  * })
113
245
  *
246
+ * r = await ftp.checkFile('./_test_upload_client/DECL_20210805055044.csv')
247
+ * console.log('ftp.checkFile', r)
248
+ *
249
+ * r = await ftp.quit()
250
+ * console.log('ftp.quit', r)
251
+ *
252
+ * }
253
+ * test()
254
+ * .catch((err) => {
255
+ * console.log(err)
256
+ * })
257
+ */
258
+ async function ftpCheckFile(fpRemote) {
259
+ return null
260
+ }
261
+
262
+
263
+ /**
264
+ * 下載伺服器指定檔案至本機
265
+ *
266
+ * @param {String} opt.fpRemote 輸入伺服器上指定檔案字串
267
+ * @param {String} opt.fpLocal 輸入本機指定檔案字串
268
+ * @param {Function} [opt.cbProcess=null] 輸入回調進度函數
269
+ * @return {Promise} 回傳Promise,resolve回傳成功訊息,reject回傳錯誤訊息
270
+ * @example
271
+ * import WFtp from './src/WFtp.mjs'
272
+ *
273
+ * async function test() {
274
+ * let r
275
+ *
276
+ * let ftp = WFtp()
277
+ * // console.log('ftp', ftp)
278
+ *
279
+ * await ftp.conn({
280
+ * hostname: st.up.hostname,
281
+ * port: st.up.port,
282
+ * username: st.up.username,
283
+ * password: st.up.password,
284
+ * })
285
+ *
286
+ * r = await ftp.download('./DECL_20210805055044.csv', './_test_download_client/DECL_20210805055044.csv', (p) => {
287
+ * console.log('ftp.download p', p.name, p.progress)
288
+ * })
289
+ * console.log('ftp.download', r)
290
+ *
291
+ * r = await ftp.quit()
292
+ * console.log('ftp.quit', r)
293
+ *
294
+ * }
295
+ * test()
296
+ * .catch((err) => {
297
+ * console.log(err)
298
+ * })
299
+ */
300
+ async function ftpDownload(fpRemote, fpLocal, cbProcess = null) {
301
+ return null
302
+ }
303
+
304
+
305
+ /**
306
+ * 上傳本機指定檔案至伺服器
307
+ *
308
+ * @param {String} opt.fpLocal 輸入本機指定檔案字串
309
+ * @param {String} opt.fpRemote 輸入伺服器上指定檔案字串
310
+ * @param {Function} [opt.cbProcess=null] 輸入回調進度函數
311
+ * @return {Promise} 回傳Promise,resolve回傳成功訊息,reject回傳錯誤訊息
312
+ * @example
313
+ * import WFtp from './src/WFtp.mjs'
314
+ *
315
+ * async function test() {
316
+ * let r
317
+ *
318
+ * let ftp = WFtp()
319
+ * // console.log('ftp', ftp)
320
+ *
321
+ * await ftp.conn({
322
+ * hostname: st.up.hostname,
323
+ * port: st.up.port,
324
+ * username: st.up.username,
325
+ * password: st.up.password,
326
+ * })
327
+ *
328
+ * r = await ftp.upload('./_test_upload_client/DECL_20210805055044.csv', './DECL_20210805055044.csv', (p) => {
329
+ * console.log('ftp.upload p', p.name, p.progress)
330
+ * })
331
+ * console.log('ftp.upload', r)
332
+ *
333
+ * r = await ftp.quit()
334
+ * console.log('ftp.quit', r)
335
+ *
336
+ * }
337
+ * test()
338
+ * .catch((err) => {
339
+ * console.log(err)
340
+ * })
341
+ */
342
+ async function ftpUpload(fpLocal, fpRemote, cbProcess) {
343
+ return null
344
+ }
345
+
346
+
347
+ /**
348
+ * 同步伺服器上指定資料夾內檔案至本機
349
+ *
350
+ * @param {String} opt.fdRemote 輸入伺服器上指定資料夾字串
351
+ * @param {String} opt.fdLocal 輸入本機指定資料夾字串
352
+ * @param {Function} [opt.cbProcess=null] 輸入回調進度函數
353
+ * @return {Promise} 回傳Promise,resolve回傳成功訊息,reject回傳錯誤訊息
354
+ * @example
355
+ * import WFtp from './src/WFtp.mjs'
356
+ *
357
+ * async function test() {
358
+ * let r
359
+ *
360
+ * let ftp = WFtp()
361
+ * // console.log('ftp', ftp)
362
+ *
363
+ * await ftp.conn({
364
+ * hostname: st.up.hostname,
365
+ * port: st.up.port,
366
+ * username: st.up.username,
367
+ * password: st.up.password,
368
+ * })
369
+ *
370
+ * r = await ftp.syncToLocal('.', './_test_download_client', (p) => {
371
+ * console.log('ftp.syncToLocal p', p.name, p.progress)
372
+ * })
373
+ * console.log('ftp.syncToLocal', r)
374
+ *
375
+ * r = await ftp.quit()
376
+ * console.log('ftp.quit', r)
377
+ *
378
+ * }
379
+ * test()
380
+ * .catch((err) => {
381
+ * console.log(err)
382
+ * })
383
+ */
384
+ async function ftpSyncToLocal(fdRemote, fdLocal, cbProcess) {
385
+ return null
386
+ }
387
+
388
+
389
+ /**
390
+ * 同步本機指定資料夾內檔案至伺服器
391
+ *
392
+ * @param {String} opt.fdLocal 輸入本機指定資料夾字串
393
+ * @param {String} opt.fdRemote 輸入伺服器上指定資料夾字串
394
+ * @param {Function} [opt.cbProcess=null] 輸入回調進度函數
395
+ * @return {Promise} 回傳Promise,resolve回傳成功訊息,reject回傳錯誤訊息
396
+ * @example
397
+ * import WFtp from './src/WFtp.mjs'
398
+ *
399
+ * async function test() {
400
+ * let r
401
+ *
402
+ * let ftp = WFtp()
403
+ * // console.log('ftp', ftp)
404
+ *
405
+ * await ftp.conn({
406
+ * hostname: st.up.hostname,
407
+ * port: st.up.port,
408
+ * username: st.up.username,
409
+ * password: st.up.password,
410
+ * })
411
+ *
412
+ * r = await ftp.syncToRemote('./_test_upload_client', '.', (p) => {
413
+ * console.log('ftp.syncToRemote p', p.name, p.progress)
414
+ * })
415
+ * console.log('ftp.syncToRemote', r)
416
+ *
417
+ * r = await ftp.quit()
418
+ * console.log('ftp.quit', r)
419
+ *
420
+ * }
421
+ * test()
422
+ * .catch((err) => {
423
+ * console.log(err)
424
+ * })
425
+ */
426
+ async function ftpSyncToRemote(fdLocal, fdRemote, cbProcess) {
427
+ return null
428
+ }
429
+
430
+
431
+ /**
432
+ * 操作FTP,包含連線、下載、資料夾內檔案同步下載、上傳、資料夾內檔案同步上傳等功能
433
+ *
434
+ * @returns {Object} 回傳FTP操作物件,包含conn、ls、stateFile、checkFile、download、syncToLocal、syncToRemote、upload、quit。
435
+ * @example
436
+ * import WFtp from './src/WFtp.mjs'
437
+ *
438
+ * async function test_up() {
439
+ * let r
440
+ *
441
+ * let ftp = WFtp()
442
+ * // console.log('ftp', ftp)
443
+ *
444
+ * await ftp.conn({
445
+ * hostname: `{hostname}`,
446
+ * port: `{port}`,
447
+ * username: `{username}`,
448
+ * password: `{password}`,
449
+ * })
450
+ *
451
+ * let fps = await ftp.ls('.')
452
+ * console.log('ftp.ls', fps[0], fps.length)
453
+ *
454
+ * r = await ftp.upload('./_test_upload_client/DECL_20210805055044.csv', './DECL_20210805055044.csv', (p) => {
455
+ * console.log('ftp.upload p', p.name, p.progress)
456
+ * })
457
+ * console.log('ftp.upload', r)
458
+ *
459
+ * r = await ftp.syncToRemote('./_test_upload_client', '.', (p) => {
460
+ * console.log('ftp.syncToRemote p', p.name, p.progress)
461
+ * })
462
+ * console.log('ftp.syncToRemote', r)
463
+ *
464
+ * r = await ftp.quit()
465
+ * console.log('ftp.quit', r)
466
+ *
467
+ * }
468
+ * test_up()
469
+ * .catch((err) => {
470
+ * console.log(err)
471
+ * })
472
+ * // ftp.ls {
473
+ * // name: 'DECL_202108.csv',
474
+ * // type: 0,
475
+ * // time: 1658366760000,
476
+ * // size: '218690',
477
+ * // owner: 'ftp',
478
+ * // group: 'ftp',
479
+ * // userPermissions: { read: true, write: true, exec: false },
480
+ * // groupPermissions: { read: true, write: true, exec: false },
481
+ * // otherPermissions: { read: true, write: true, exec: false }
482
+ * // } 73
483
+ * // ftp.upload p DECL_20210805055044.csv 75.71339448693362
484
+ * // drain
485
+ * // ftp.upload p DECL_20210805055044.csv 100
486
+ * // ftp.upload ok
487
+ * // ftp.syncToRemote { num: 0, files: [] }
488
+ * // ftp.quit { code: 221, text: '221 Goodbye.', isMark: false, isError: false }
489
+ *
490
+ * async function test_dw() {
491
+ * let r
492
+ *
493
+ * let ftp = WFtp()
494
+ * // console.log('ftp', ftp)
495
+ *
496
+ * await ftp.conn({
497
+ * hostname: `{hostname}`,
498
+ * port: `{port}`,
499
+ * username: `{username}`,
500
+ * password: `{password}`,
501
+ * })
502
+ *
503
+ * let fps = await ftp.ls('.')
504
+ * console.log('ftp.ls', fps[0], fps.length)
505
+ *
506
+ * r = await ftp.download('./DECL_20210805055044.csv', './_test_download_client/DECL_20210805055044.csv', (p) => {
507
+ * console.log('ftp.download p', p.name, p.progress)
508
+ * })
509
+ * console.log('ftp.download', r)
510
+ *
511
+ * r = await ftp.syncToLocal('.', './_test_download_client', (p) => {
512
+ * console.log('ftp.syncToLocal p', p.name, p.progress)
513
+ * })
514
+ * console.log('ftp.syncToLocal', r)
515
+ *
516
+ * r = await ftp.quit()
517
+ * console.log('ftp.quit', r)
518
+ *
519
+ * }
520
+ * test_dw()
521
+ * .catch((err) => {
522
+ * console.log(err)
523
+ * })
524
+ * // ftp.ls {
525
+ * // name: 'DECL_202108.csv',
526
+ * // type: 0,
527
+ * // time: 1658302140000,
528
+ * // size: '218690',
529
+ * // owner: 'ftp',
530
+ * // group: 'ftp',
531
+ * // userPermissions: { read: true, write: true, exec: false },
532
+ * // groupPermissions: { read: true, write: true, exec: false },
533
+ * // otherPermissions: { read: true, write: true, exec: false }
534
+ * // } 74
535
+ * // ftp.download p DECL_20210805055044.csv 4.7320871554333515
536
+ * // ftp.download p DECL_20210805055044.csv 9.464174310866703
537
+ * // ftp.download p DECL_20210805055044.csv 14.196261466300053
538
+ * // ftp.download p DECL_20210805055044.csv 18.928348621733406
539
+ * // ftp.download p DECL_20210805055044.csv 23.660435777166754
540
+ * // ftp.download p DECL_20210805055044.csv 28.392522932600105
541
+ * // ftp.download p DECL_20210805055044.csv 33.12461008803346
542
+ * // ftp.download p DECL_20210805055044.csv 37.85669724346681
543
+ * // ftp.download p DECL_20210805055044.csv 42.58878439890016
544
+ * // ftp.download p DECL_20210805055044.csv 47.32087155433351
545
+ * // ftp.download p DECL_20210805055044.csv 52.05295870976686
546
+ * // ftp.download p DECL_20210805055044.csv 56.78504586520021
547
+ * // ftp.download p DECL_20210805055044.csv 61.517133020633565
548
+ * // ftp.download p DECL_20210805055044.csv 66.24922017606691
549
+ * // ftp.download p DECL_20210805055044.csv 70.98130733150026
550
+ * // ftp.download p DECL_20210805055044.csv 75.71339448693362
551
+ * // ftp.download p DECL_20210805055044.csv 80.44548164236697
552
+ * // ftp.download p DECL_20210805055044.csv 85.17756879780032
553
+ * // ftp.download p DECL_20210805055044.csv 89.90965595323367
554
+ * // ftp.download p DECL_20210805055044.csv 94.64174310866701
555
+ * // ftp.download p DECL_20210805055044.csv 99.37383026410038
556
+ * // ftp.download p DECL_20210805055044.csv 100
557
+ * // ftp.download ok
558
+ * // ftp.syncToLocal { num: 0, files: [] }
559
+ * // ftp.quit { code: 221, text: '221 Goodbye.', isMark: false, isError: false }
560
+ *
114
561
  */
115
562
  function WFtp() {
563
+ let doc = {
564
+ doc_ftpConn: ftpConn,
565
+ doc_ftpLs: ftpLs,
566
+ doc_ftpQuit: ftpQuit,
567
+ doc_ftpStateFile: ftpStateFile,
568
+ doc_ftpCheckFile: ftpCheckFile,
569
+ doc_ftpDownload: ftpDownload,
570
+ doc_ftpUpload: ftpUpload,
571
+ doc_ftpSyncToLocal: ftpSyncToLocal,
572
+ doc_ftpSyncToRemote: ftpSyncToRemote,
573
+ }
116
574
 
117
575
  function WFtpCore() {
118
576
  let Ftp = null
@@ -154,11 +612,12 @@ function WFtp() {
154
612
 
155
613
  try {
156
614
  Ftp = new Jsftp({
157
- host: hostname,
615
+ host: hostname, //hostname or ip
158
616
  port, // defaults to 21
159
617
  user: username, // defaults to "anonymous"
160
618
  pass: password, // defaults to "@anonymous"
161
619
  })
620
+ Ftp.__doc__ = doc
162
621
  pm.resolve('ok')
163
622
  }
164
623
  catch (err) {
@@ -169,7 +628,7 @@ function WFtp() {
169
628
  }
170
629
 
171
630
 
172
- async function ftpLs(remoteFd = '.') {
631
+ async function ftpLs(fdRemote = '.') {
173
632
 
174
633
  //pm
175
634
  let pm = genPm()
@@ -180,7 +639,7 @@ function WFtp() {
180
639
  return pm
181
640
  }
182
641
 
183
- Ftp.ls(remoteFd, (err, res) => {
642
+ Ftp.ls(fdRemote, (err, res) => {
184
643
  if (err) {
185
644
  pm.reject(err)
186
645
  }
@@ -249,7 +708,7 @@ function WFtp() {
249
708
  }
250
709
 
251
710
 
252
- async function ftpDownload(fpRemote, fpLocal, cbProcess) {
711
+ async function ftpDownload(fpRemote, fpLocal, cbProcess = null) {
253
712
 
254
713
  //pm
255
714
  let pm = genPm()
@@ -652,7 +1111,7 @@ export default WFtp
652
1111
  <br class="clear">
653
1112
 
654
1113
  <footer>
655
- Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.10</a> on Sat Jul 23 2022 13:03:06 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
1114
+ 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.
656
1115
  </footer>
657
1116
 
658
1117
  <script>prettyPrint();</script>