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/README.md +100 -65
- package/dist/w-ftp.umd.js +2 -8
- package/dist/w-ftp.umd.js.map +1 -1
- package/docs/WFtp.mjs.html +623 -45
- package/docs/global.html +1980 -48
- 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 +9 -2
- package/src/WFtp.mjs +621 -43
- package/src/jsftp.js +5 -1
- package/toolg/gDistRollup.mjs +20 -4
package/docs/WFtp.mjs.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#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">
|
|
@@ -64,55 +64,568 @@ 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
|
-
|
|
67
|
+
import ot from 'dayjs'
|
|
68
68
|
import Jsftp from './jsftp.js'
|
|
69
|
-
console.log('Jsftp', Jsftp)
|
|
70
69
|
|
|
71
70
|
|
|
72
71
|
/**
|
|
73
|
-
*
|
|
72
|
+
* 連線至FPT伺服器
|
|
74
73
|
*
|
|
75
|
-
* @param {String} fp 輸入檔案路徑字串
|
|
76
74
|
* @param {Object} [opt={}] 輸入設定物件,預設{}
|
|
77
|
-
* @param {String}
|
|
78
|
-
* @
|
|
75
|
+
* @param {String} opt.hostname='' 輸入hostname字串
|
|
76
|
+
* @param {Number} opt.port='' 輸入port正整數
|
|
77
|
+
* @param {String} opt.username='' 輸入帳號字串
|
|
78
|
+
* @param {String} opt.password='' 輸入密碼字串
|
|
79
|
+
* @return {Promise} 回傳Promise,resolve回傳成功訊息,reject回傳錯誤訊息
|
|
79
80
|
* @example
|
|
80
81
|
* import WFtp from './src/WFtp.mjs'
|
|
81
82
|
*
|
|
82
83
|
* async function test() {
|
|
84
|
+
* let r
|
|
83
85
|
*
|
|
84
|
-
*
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
*
|
|
90
|
-
*
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
* //
|
|
95
|
-
*
|
|
96
|
-
*
|
|
97
|
-
*
|
|
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
|
-
* // ]
|
|
86
|
+
* let ftp = WFtp()
|
|
87
|
+
* // console.log('ftp', ftp)
|
|
88
|
+
*
|
|
89
|
+
* await ftp.conn({
|
|
90
|
+
* hostname: st.up.hostname,
|
|
91
|
+
* port: st.up.port,
|
|
92
|
+
* username: st.up.username,
|
|
93
|
+
* password: st.up.password,
|
|
94
|
+
* })
|
|
95
|
+
*
|
|
96
|
+
* //actions
|
|
97
|
+
*
|
|
98
|
+
* r = await ftp.quit()
|
|
99
|
+
* console.log('ftp.quit', r)
|
|
107
100
|
*
|
|
108
101
|
* }
|
|
109
102
|
* test()
|
|
110
103
|
* .catch((err) => {
|
|
111
|
-
* console.log(
|
|
104
|
+
* console.log(err)
|
|
112
105
|
* })
|
|
113
106
|
*
|
|
114
107
|
*/
|
|
108
|
+
async function conn(opt = {}) {
|
|
109
|
+
return null
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* 遍歷伺服器上指定資料夾內檔案清單資訊
|
|
115
|
+
*
|
|
116
|
+
* @param {String} opt.fdRemote 輸入伺服器上指定資料夾字串
|
|
117
|
+
* @return {Promise} 回傳Promise,resolve回傳檔案清單資訊,reject回傳錯誤訊息
|
|
118
|
+
* @example
|
|
119
|
+
* import WFtp from './src/WFtp.mjs'
|
|
120
|
+
*
|
|
121
|
+
* async function test() {
|
|
122
|
+
* let r
|
|
123
|
+
*
|
|
124
|
+
* let ftp = WFtp()
|
|
125
|
+
* // console.log('ftp', ftp)
|
|
126
|
+
*
|
|
127
|
+
* await ftp.conn({
|
|
128
|
+
* hostname: st.up.hostname,
|
|
129
|
+
* port: st.up.port,
|
|
130
|
+
* username: st.up.username,
|
|
131
|
+
* password: st.up.password,
|
|
132
|
+
* })
|
|
133
|
+
*
|
|
134
|
+
* let fps = await ftp.ls('.')
|
|
135
|
+
* console.log('ftp.ls', fps[0], fps.length)
|
|
136
|
+
*
|
|
137
|
+
* r = await ftp.quit()
|
|
138
|
+
* console.log('ftp.quit', r)
|
|
139
|
+
*
|
|
140
|
+
* }
|
|
141
|
+
* test()
|
|
142
|
+
* .catch((err) => {
|
|
143
|
+
* console.log(err)
|
|
144
|
+
* })
|
|
145
|
+
*
|
|
146
|
+
*/
|
|
147
|
+
async function ls(fdRemote = '.') {
|
|
148
|
+
return null
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* 關閉與伺服器連線
|
|
154
|
+
*
|
|
155
|
+
* @return {Promise} 回傳Promise,resolve回傳成功訊息,reject回傳錯誤訊息
|
|
156
|
+
* @example
|
|
157
|
+
* import WFtp from './src/WFtp.mjs'
|
|
158
|
+
*
|
|
159
|
+
* async function test() {
|
|
160
|
+
* let r
|
|
161
|
+
*
|
|
162
|
+
* let ftp = WFtp()
|
|
163
|
+
* // console.log('ftp', ftp)
|
|
164
|
+
*
|
|
165
|
+
* await ftp.conn({
|
|
166
|
+
* hostname: st.up.hostname,
|
|
167
|
+
* port: st.up.port,
|
|
168
|
+
* username: st.up.username,
|
|
169
|
+
* password: st.up.password,
|
|
170
|
+
* })
|
|
171
|
+
*
|
|
172
|
+
* //actions
|
|
173
|
+
*
|
|
174
|
+
* r = await ftp.quit()
|
|
175
|
+
* console.log('ftp.quit', r)
|
|
176
|
+
*
|
|
177
|
+
* }
|
|
178
|
+
* test()
|
|
179
|
+
* .catch((err) => {
|
|
180
|
+
* console.log(err)
|
|
181
|
+
* })
|
|
182
|
+
*/
|
|
183
|
+
async function quit() {
|
|
184
|
+
return null
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* 取得伺服器指定檔案資訊
|
|
190
|
+
*
|
|
191
|
+
* @param {String} opt.fpRemote 輸入伺服器上指定檔案字串
|
|
192
|
+
* @return {Promise} 回傳Promise,resolve回傳檔案資訊,reject回傳錯誤訊息
|
|
193
|
+
* @example
|
|
194
|
+
* import WFtp from './src/WFtp.mjs'
|
|
195
|
+
*
|
|
196
|
+
* async function test() {
|
|
197
|
+
* let r
|
|
198
|
+
*
|
|
199
|
+
* let ftp = WFtp()
|
|
200
|
+
* // console.log('ftp', ftp)
|
|
201
|
+
*
|
|
202
|
+
* await ftp.conn({
|
|
203
|
+
* hostname: st.up.hostname,
|
|
204
|
+
* port: st.up.port,
|
|
205
|
+
* username: st.up.username,
|
|
206
|
+
* password: st.up.password,
|
|
207
|
+
* })
|
|
208
|
+
*
|
|
209
|
+
* r = await ftp.stateFile('./_test_upload_client/DECL_20210805055044.csv')
|
|
210
|
+
* console.log('ftp.stateFile', r)
|
|
211
|
+
*
|
|
212
|
+
* r = await ftp.quit()
|
|
213
|
+
* console.log('ftp.quit', r)
|
|
214
|
+
*
|
|
215
|
+
* }
|
|
216
|
+
* test()
|
|
217
|
+
* .catch((err) => {
|
|
218
|
+
* console.log(err)
|
|
219
|
+
* })
|
|
220
|
+
*/
|
|
221
|
+
async function stateFile(fpRemote) {
|
|
222
|
+
return null
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* 確認伺服器指定檔案是否存在
|
|
228
|
+
*
|
|
229
|
+
* @param {String} opt.fpRemote 輸入伺服器上指定檔案字串
|
|
230
|
+
* @return {Promise} 回傳Promise,resolve回傳指定檔案是否存在布林值,reject回傳錯誤訊息
|
|
231
|
+
* @example
|
|
232
|
+
* import WFtp from './src/WFtp.mjs'
|
|
233
|
+
*
|
|
234
|
+
* async function test() {
|
|
235
|
+
* let r
|
|
236
|
+
*
|
|
237
|
+
* let ftp = WFtp()
|
|
238
|
+
* // console.log('ftp', ftp)
|
|
239
|
+
*
|
|
240
|
+
* await ftp.conn({
|
|
241
|
+
* hostname: st.up.hostname,
|
|
242
|
+
* port: st.up.port,
|
|
243
|
+
* username: st.up.username,
|
|
244
|
+
* password: st.up.password,
|
|
245
|
+
* })
|
|
246
|
+
*
|
|
247
|
+
* r = await ftp.isFile('./_test_upload_client/DECL_20210805055044.csv')
|
|
248
|
+
* console.log('ftp.isFile', r)
|
|
249
|
+
*
|
|
250
|
+
* r = await ftp.quit()
|
|
251
|
+
* console.log('ftp.quit', r)
|
|
252
|
+
*
|
|
253
|
+
* }
|
|
254
|
+
* test()
|
|
255
|
+
* .catch((err) => {
|
|
256
|
+
* console.log(err)
|
|
257
|
+
* })
|
|
258
|
+
*/
|
|
259
|
+
async function isFile(fpRemote) {
|
|
260
|
+
return null
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* 確認伺服器指定資料夾是否存在
|
|
266
|
+
*
|
|
267
|
+
* @param {String} opt.fpRemote 輸入伺服器上指定資料夾字串
|
|
268
|
+
* @return {Promise} 回傳Promise,resolve回傳指定資料夾是否存在布林值,reject回傳錯誤訊息
|
|
269
|
+
* @example
|
|
270
|
+
* import WFtp from './src/WFtp.mjs'
|
|
271
|
+
*
|
|
272
|
+
* async function test() {
|
|
273
|
+
* let r
|
|
274
|
+
*
|
|
275
|
+
* let ftp = WFtp()
|
|
276
|
+
* // console.log('ftp', ftp)
|
|
277
|
+
*
|
|
278
|
+
* await ftp.conn({
|
|
279
|
+
* hostname: st.up.hostname,
|
|
280
|
+
* port: st.up.port,
|
|
281
|
+
* username: st.up.username,
|
|
282
|
+
* password: st.up.password,
|
|
283
|
+
* })
|
|
284
|
+
*
|
|
285
|
+
* r = await ftp.isFolder('./_test_upload_client')
|
|
286
|
+
* console.log('ftp.isFolder', r)
|
|
287
|
+
*
|
|
288
|
+
* r = await ftp.quit()
|
|
289
|
+
* console.log('ftp.quit', r)
|
|
290
|
+
*
|
|
291
|
+
* }
|
|
292
|
+
* test()
|
|
293
|
+
* .catch((err) => {
|
|
294
|
+
* console.log(err)
|
|
295
|
+
* })
|
|
296
|
+
*/
|
|
297
|
+
async function isFolder(fpRemote) {
|
|
298
|
+
return null
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
|
|
302
|
+
/**
|
|
303
|
+
* 下載伺服器指定檔案至本機
|
|
304
|
+
*
|
|
305
|
+
* @param {String} opt.fpRemote 輸入伺服器上指定檔案字串
|
|
306
|
+
* @param {String} opt.fpLocal 輸入本機指定檔案字串
|
|
307
|
+
* @param {Function} [opt.cbProcess=null] 輸入回調進度函數
|
|
308
|
+
* @return {Promise} 回傳Promise,resolve回傳成功訊息,reject回傳錯誤訊息
|
|
309
|
+
* @example
|
|
310
|
+
* import WFtp from './src/WFtp.mjs'
|
|
311
|
+
*
|
|
312
|
+
* async function test() {
|
|
313
|
+
* let r
|
|
314
|
+
*
|
|
315
|
+
* let ftp = WFtp()
|
|
316
|
+
* // console.log('ftp', ftp)
|
|
317
|
+
*
|
|
318
|
+
* await ftp.conn({
|
|
319
|
+
* hostname: st.up.hostname,
|
|
320
|
+
* port: st.up.port,
|
|
321
|
+
* username: st.up.username,
|
|
322
|
+
* password: st.up.password,
|
|
323
|
+
* })
|
|
324
|
+
*
|
|
325
|
+
* r = await ftp.download('./DECL_20210805055044.csv', './_test_download_client/DECL_20210805055044.csv', (p) => {
|
|
326
|
+
* console.log('ftp.download p', p.name, p.progress)
|
|
327
|
+
* })
|
|
328
|
+
* console.log('ftp.download', r)
|
|
329
|
+
*
|
|
330
|
+
* r = await ftp.quit()
|
|
331
|
+
* console.log('ftp.quit', r)
|
|
332
|
+
*
|
|
333
|
+
* }
|
|
334
|
+
* test()
|
|
335
|
+
* .catch((err) => {
|
|
336
|
+
* console.log(err)
|
|
337
|
+
* })
|
|
338
|
+
*/
|
|
339
|
+
async function download(fpRemote, fpLocal, cbProcess = null) {
|
|
340
|
+
return null
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
|
|
344
|
+
/**
|
|
345
|
+
* 上傳本機指定檔案至伺服器
|
|
346
|
+
*
|
|
347
|
+
* @param {String} opt.fpLocal 輸入本機指定檔案字串
|
|
348
|
+
* @param {String} opt.fpRemote 輸入伺服器上指定檔案字串
|
|
349
|
+
* @param {Function} [opt.cbProcess=null] 輸入回調進度函數
|
|
350
|
+
* @return {Promise} 回傳Promise,resolve回傳成功訊息,reject回傳錯誤訊息
|
|
351
|
+
* @example
|
|
352
|
+
* import WFtp from './src/WFtp.mjs'
|
|
353
|
+
*
|
|
354
|
+
* async function test() {
|
|
355
|
+
* let r
|
|
356
|
+
*
|
|
357
|
+
* let ftp = WFtp()
|
|
358
|
+
* // console.log('ftp', ftp)
|
|
359
|
+
*
|
|
360
|
+
* await ftp.conn({
|
|
361
|
+
* hostname: st.up.hostname,
|
|
362
|
+
* port: st.up.port,
|
|
363
|
+
* username: st.up.username,
|
|
364
|
+
* password: st.up.password,
|
|
365
|
+
* })
|
|
366
|
+
*
|
|
367
|
+
* r = await ftp.upload('./_test_upload_client/DECL_20210805055044.csv', './DECL_20210805055044.csv', (p) => {
|
|
368
|
+
* console.log('ftp.upload p', p.name, p.progress)
|
|
369
|
+
* })
|
|
370
|
+
* console.log('ftp.upload', r)
|
|
371
|
+
*
|
|
372
|
+
* r = await ftp.quit()
|
|
373
|
+
* console.log('ftp.quit', r)
|
|
374
|
+
*
|
|
375
|
+
* }
|
|
376
|
+
* test()
|
|
377
|
+
* .catch((err) => {
|
|
378
|
+
* console.log(err)
|
|
379
|
+
* })
|
|
380
|
+
*/
|
|
381
|
+
async function upload(fpLocal, fpRemote, cbProcess) {
|
|
382
|
+
return null
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
|
|
386
|
+
/**
|
|
387
|
+
* 同步伺服器上指定資料夾內檔案至本機
|
|
388
|
+
*
|
|
389
|
+
* @param {String} opt.fdRemote 輸入伺服器上指定資料夾字串
|
|
390
|
+
* @param {String} opt.fdLocal 輸入本機指定資料夾字串
|
|
391
|
+
* @param {Function} [opt.cbProcess=null] 輸入回調進度函數
|
|
392
|
+
* @return {Promise} 回傳Promise,resolve回傳成功訊息,reject回傳錯誤訊息
|
|
393
|
+
* @example
|
|
394
|
+
* import WFtp from './src/WFtp.mjs'
|
|
395
|
+
*
|
|
396
|
+
* async function test() {
|
|
397
|
+
* let r
|
|
398
|
+
*
|
|
399
|
+
* let ftp = WFtp()
|
|
400
|
+
* // console.log('ftp', ftp)
|
|
401
|
+
*
|
|
402
|
+
* await ftp.conn({
|
|
403
|
+
* hostname: st.up.hostname,
|
|
404
|
+
* port: st.up.port,
|
|
405
|
+
* username: st.up.username,
|
|
406
|
+
* password: st.up.password,
|
|
407
|
+
* })
|
|
408
|
+
*
|
|
409
|
+
* r = await ftp.syncToLocal('.', './_test_download_client', (p) => {
|
|
410
|
+
* console.log('ftp.syncToLocal p', p.name, p.progress)
|
|
411
|
+
* })
|
|
412
|
+
* console.log('ftp.syncToLocal', r)
|
|
413
|
+
*
|
|
414
|
+
* r = await ftp.quit()
|
|
415
|
+
* console.log('ftp.quit', r)
|
|
416
|
+
*
|
|
417
|
+
* }
|
|
418
|
+
* test()
|
|
419
|
+
* .catch((err) => {
|
|
420
|
+
* console.log(err)
|
|
421
|
+
* })
|
|
422
|
+
*/
|
|
423
|
+
async function syncToLocal(fdRemote, fdLocal, cbProcess) {
|
|
424
|
+
return null
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
|
|
428
|
+
/**
|
|
429
|
+
* 同步本機指定資料夾內檔案至伺服器
|
|
430
|
+
*
|
|
431
|
+
* @param {String} opt.fdLocal 輸入本機指定資料夾字串
|
|
432
|
+
* @param {String} opt.fdRemote 輸入伺服器上指定資料夾字串
|
|
433
|
+
* @param {Function} [opt.cbProcess=null] 輸入回調進度函數
|
|
434
|
+
* @return {Promise} 回傳Promise,resolve回傳成功訊息,reject回傳錯誤訊息
|
|
435
|
+
* @example
|
|
436
|
+
* import WFtp from './src/WFtp.mjs'
|
|
437
|
+
*
|
|
438
|
+
* async function test() {
|
|
439
|
+
* let r
|
|
440
|
+
*
|
|
441
|
+
* let ftp = WFtp()
|
|
442
|
+
* // console.log('ftp', ftp)
|
|
443
|
+
*
|
|
444
|
+
* await ftp.conn({
|
|
445
|
+
* hostname: st.up.hostname,
|
|
446
|
+
* port: st.up.port,
|
|
447
|
+
* username: st.up.username,
|
|
448
|
+
* password: st.up.password,
|
|
449
|
+
* })
|
|
450
|
+
*
|
|
451
|
+
* r = await ftp.syncToRemote('./_test_upload_client', '.', (p) => {
|
|
452
|
+
* console.log('ftp.syncToRemote p', p.name, p.progress)
|
|
453
|
+
* })
|
|
454
|
+
* console.log('ftp.syncToRemote', r)
|
|
455
|
+
*
|
|
456
|
+
* r = await ftp.quit()
|
|
457
|
+
* console.log('ftp.quit', r)
|
|
458
|
+
*
|
|
459
|
+
* }
|
|
460
|
+
* test()
|
|
461
|
+
* .catch((err) => {
|
|
462
|
+
* console.log(err)
|
|
463
|
+
* })
|
|
464
|
+
*/
|
|
465
|
+
async function syncToRemote(fdLocal, fdRemote, cbProcess) {
|
|
466
|
+
return null
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
|
|
470
|
+
/**
|
|
471
|
+
* 操作FTP,包含連線、下載、資料夾內檔案同步下載、上傳、資料夾內檔案同步上傳等功能
|
|
472
|
+
*
|
|
473
|
+
* @returns {Object} 回傳FTP操作物件,包含conn、ls、stateFile、isFile、download、syncToLocal、syncToRemote、upload、quit。
|
|
474
|
+
* @example
|
|
475
|
+
* import WFtp from './src/WFtp.mjs'
|
|
476
|
+
*
|
|
477
|
+
* async function test_dw() {
|
|
478
|
+
* let r
|
|
479
|
+
*
|
|
480
|
+
* let ftp = WFtp()
|
|
481
|
+
* // console.log('ftp', ftp)
|
|
482
|
+
*
|
|
483
|
+
* await ftp.conn({
|
|
484
|
+
* hostname: `{hostname}`,
|
|
485
|
+
* port: `{port}`,
|
|
486
|
+
* username: `{username}`,
|
|
487
|
+
* password: `{password}`,
|
|
488
|
+
* })
|
|
489
|
+
*
|
|
490
|
+
* async function core() {
|
|
491
|
+
*
|
|
492
|
+
* let fps = await ftp.ls('.')
|
|
493
|
+
* console.log('ftp.ls', fps[0], fps.length)
|
|
494
|
+
*
|
|
495
|
+
* r = await ftp.download('./DECL_20210805055044.csv', './_test_download_client/DECL_20210805055044.csv', (p) => {
|
|
496
|
+
* console.log('ftp.download p', p.name, p.progress)
|
|
497
|
+
* })
|
|
498
|
+
* console.log('ftp.download', r)
|
|
499
|
+
*
|
|
500
|
+
* r = await ftp.syncToLocal('.', './_test_download_client', (p) => {
|
|
501
|
+
* console.log('ftp.syncToLocal p', p.name, p.progress)
|
|
502
|
+
* })
|
|
503
|
+
* console.log('ftp.syncToLocal', r)
|
|
504
|
+
*
|
|
505
|
+
* }
|
|
506
|
+
* await core()
|
|
507
|
+
* .catch((err) => {
|
|
508
|
+
* console.log(err)
|
|
509
|
+
* })
|
|
510
|
+
*
|
|
511
|
+
* r = await ftp.quit()
|
|
512
|
+
* console.log('ftp.quit', r)
|
|
513
|
+
*
|
|
514
|
+
* }
|
|
515
|
+
* test_dw()
|
|
516
|
+
* .catch((err) => {
|
|
517
|
+
* console.log(err)
|
|
518
|
+
* })
|
|
519
|
+
* // ftp.ls {
|
|
520
|
+
* // name: 'DECL_202108.csv',
|
|
521
|
+
* // type: 0,
|
|
522
|
+
* // time: 1658302140000,
|
|
523
|
+
* // size: '218690',
|
|
524
|
+
* // owner: 'ftp',
|
|
525
|
+
* // group: 'ftp',
|
|
526
|
+
* // userPermissions: { read: true, write: true, exec: false },
|
|
527
|
+
* // groupPermissions: { read: true, write: true, exec: false },
|
|
528
|
+
* // otherPermissions: { read: true, write: true, exec: false }
|
|
529
|
+
* // } 74
|
|
530
|
+
* // ftp.download p DECL_20210805055044.csv 4.7320871554333515
|
|
531
|
+
* // ftp.download p DECL_20210805055044.csv 9.464174310866703
|
|
532
|
+
* // ftp.download p DECL_20210805055044.csv 14.196261466300053
|
|
533
|
+
* // ftp.download p DECL_20210805055044.csv 18.928348621733406
|
|
534
|
+
* // ftp.download p DECL_20210805055044.csv 23.660435777166754
|
|
535
|
+
* // ftp.download p DECL_20210805055044.csv 28.392522932600105
|
|
536
|
+
* // ftp.download p DECL_20210805055044.csv 33.12461008803346
|
|
537
|
+
* // ftp.download p DECL_20210805055044.csv 37.85669724346681
|
|
538
|
+
* // ftp.download p DECL_20210805055044.csv 42.58878439890016
|
|
539
|
+
* // ftp.download p DECL_20210805055044.csv 47.32087155433351
|
|
540
|
+
* // ftp.download p DECL_20210805055044.csv 52.05295870976686
|
|
541
|
+
* // ftp.download p DECL_20210805055044.csv 56.78504586520021
|
|
542
|
+
* // ftp.download p DECL_20210805055044.csv 61.517133020633565
|
|
543
|
+
* // ftp.download p DECL_20210805055044.csv 66.24922017606691
|
|
544
|
+
* // ftp.download p DECL_20210805055044.csv 70.98130733150026
|
|
545
|
+
* // ftp.download p DECL_20210805055044.csv 75.71339448693362
|
|
546
|
+
* // ftp.download p DECL_20210805055044.csv 80.44548164236697
|
|
547
|
+
* // ftp.download p DECL_20210805055044.csv 85.17756879780032
|
|
548
|
+
* // ftp.download p DECL_20210805055044.csv 89.90965595323367
|
|
549
|
+
* // ftp.download p DECL_20210805055044.csv 94.64174310866701
|
|
550
|
+
* // ftp.download p DECL_20210805055044.csv 99.37383026410038
|
|
551
|
+
* // ftp.download p DECL_20210805055044.csv 100
|
|
552
|
+
* // ftp.download ok
|
|
553
|
+
* // ftp.syncToLocal { num: 0, files: [] }
|
|
554
|
+
* // ftp.quit { code: 221, text: '221 Goodbye.', isMark: false, isError: false }
|
|
555
|
+
*
|
|
556
|
+
* async function test_up() {
|
|
557
|
+
* let r
|
|
558
|
+
*
|
|
559
|
+
* let ftp = WFtp()
|
|
560
|
+
* // console.log('ftp', ftp)
|
|
561
|
+
*
|
|
562
|
+
* await ftp.conn({
|
|
563
|
+
* hostname: `{hostname}`,
|
|
564
|
+
* port: `{port}`,
|
|
565
|
+
* username: `{username}`,
|
|
566
|
+
* password: `{password}`,
|
|
567
|
+
* })
|
|
568
|
+
*
|
|
569
|
+
* async function core() {
|
|
570
|
+
*
|
|
571
|
+
* let fps = await ftp.ls('.')
|
|
572
|
+
* console.log('ftp.ls', fps[0], fps.length)
|
|
573
|
+
*
|
|
574
|
+
* r = await ftp.upload('./_test_upload_client/DECL_20210805055044.csv', './DECL_20210805055044.csv', (p) => {
|
|
575
|
+
* console.log('ftp.upload p', p.name, p.progress)
|
|
576
|
+
* })
|
|
577
|
+
* console.log('ftp.upload', r)
|
|
578
|
+
*
|
|
579
|
+
* r = await ftp.syncToRemote('./_test_upload_client', '.', (p) => {
|
|
580
|
+
* console.log('ftp.syncToRemote p', p.name, p.progress)
|
|
581
|
+
* })
|
|
582
|
+
* console.log('ftp.syncToRemote', r)
|
|
583
|
+
*
|
|
584
|
+
* }
|
|
585
|
+
* await core()
|
|
586
|
+
* .catch((err) => {
|
|
587
|
+
* console.log(err)
|
|
588
|
+
* })
|
|
589
|
+
*
|
|
590
|
+
* r = await ftp.quit()
|
|
591
|
+
* console.log('ftp.quit', r)
|
|
592
|
+
*
|
|
593
|
+
* }
|
|
594
|
+
* test_up()
|
|
595
|
+
* .catch((err) => {
|
|
596
|
+
* console.log(err)
|
|
597
|
+
* })
|
|
598
|
+
* // ftp.ls {
|
|
599
|
+
* // name: 'DECL_202108.csv',
|
|
600
|
+
* // type: 0,
|
|
601
|
+
* // time: 1658366760000,
|
|
602
|
+
* // size: '218690',
|
|
603
|
+
* // owner: 'ftp',
|
|
604
|
+
* // group: 'ftp',
|
|
605
|
+
* // userPermissions: { read: true, write: true, exec: false },
|
|
606
|
+
* // groupPermissions: { read: true, write: true, exec: false },
|
|
607
|
+
* // otherPermissions: { read: true, write: true, exec: false }
|
|
608
|
+
* // } 73
|
|
609
|
+
* // ftp.upload p DECL_20210805055044.csv 75.71339448693362
|
|
610
|
+
* // ftp.upload p DECL_20210805055044.csv 100
|
|
611
|
+
* // ftp.upload ok
|
|
612
|
+
* // ftp.syncToRemote { num: 0, files: [] }
|
|
613
|
+
* // ftp.quit { code: 221, text: '221 Goodbye.', isMark: false, isError: false }
|
|
614
|
+
*
|
|
615
|
+
*/
|
|
115
616
|
function WFtp() {
|
|
617
|
+
let doc = {
|
|
618
|
+
doc_conn: conn,
|
|
619
|
+
doc_ls: ls,
|
|
620
|
+
doc_quit: quit,
|
|
621
|
+
doc_stateFile: stateFile,
|
|
622
|
+
doc_isFile: isFile,
|
|
623
|
+
doc_isFolder: isFolder,
|
|
624
|
+
doc_download: download,
|
|
625
|
+
doc_upload: upload,
|
|
626
|
+
doc_syncToLocal: syncToLocal,
|
|
627
|
+
doc_syncToRemote: syncToRemote,
|
|
628
|
+
}
|
|
116
629
|
|
|
117
630
|
function WFtpCore() {
|
|
118
631
|
let Ftp = null
|
|
@@ -154,11 +667,12 @@ function WFtp() {
|
|
|
154
667
|
|
|
155
668
|
try {
|
|
156
669
|
Ftp = new Jsftp({
|
|
157
|
-
host: hostname,
|
|
670
|
+
host: hostname, //hostname or ip
|
|
158
671
|
port, // defaults to 21
|
|
159
672
|
user: username, // defaults to "anonymous"
|
|
160
673
|
pass: password, // defaults to "@anonymous"
|
|
161
674
|
})
|
|
675
|
+
Ftp.__doc__ = doc
|
|
162
676
|
pm.resolve('ok')
|
|
163
677
|
}
|
|
164
678
|
catch (err) {
|
|
@@ -169,7 +683,7 @@ function WFtp() {
|
|
|
169
683
|
}
|
|
170
684
|
|
|
171
685
|
|
|
172
|
-
async function ftpLs(
|
|
686
|
+
async function ftpLs(fdRemote = '.') {
|
|
173
687
|
|
|
174
688
|
//pm
|
|
175
689
|
let pm = genPm()
|
|
@@ -180,11 +694,17 @@ function WFtp() {
|
|
|
180
694
|
return pm
|
|
181
695
|
}
|
|
182
696
|
|
|
183
|
-
Ftp.ls(
|
|
697
|
+
Ftp.ls(fdRemote, (err, res) => {
|
|
184
698
|
if (err) {
|
|
185
699
|
pm.reject(err)
|
|
186
700
|
}
|
|
187
701
|
else {
|
|
702
|
+
res = map(res, (v) => {
|
|
703
|
+
let d = ot(v.time) //jsfpt解析時間係基於ls, 其檔案變更時間精度只至分而沒有秒, 故無法提供精確的檔案變更時間
|
|
704
|
+
v.ctime = d.format('YYYY-MM-DDTHH:mm:ssZ') //添加UTC時間
|
|
705
|
+
v.isFolder = ftpIsFolderCore(v)
|
|
706
|
+
return v
|
|
707
|
+
})
|
|
188
708
|
pm.resolve(res)
|
|
189
709
|
}
|
|
190
710
|
})
|
|
@@ -237,19 +757,62 @@ function WFtp() {
|
|
|
237
757
|
}
|
|
238
758
|
|
|
239
759
|
|
|
240
|
-
|
|
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) {
|
|
241
795
|
|
|
242
796
|
//ftpStateFile
|
|
243
797
|
let file = await ftpStateFile(fpRemote)
|
|
244
798
|
|
|
245
|
-
//
|
|
246
|
-
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)
|
|
247
810
|
|
|
248
811
|
return b
|
|
249
812
|
}
|
|
250
813
|
|
|
251
814
|
|
|
252
|
-
async function ftpDownload(fpRemote, fpLocal, cbProcess) {
|
|
815
|
+
async function ftpDownload(fpRemote, fpLocal, cbProcess = null) {
|
|
253
816
|
|
|
254
817
|
//pm
|
|
255
818
|
let pm = genPm()
|
|
@@ -284,6 +847,22 @@ function WFtp() {
|
|
|
284
847
|
let file = await ftpStateFile(fpRemote)
|
|
285
848
|
// console.log('file', file)
|
|
286
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
|
+
|
|
287
866
|
//fileSize
|
|
288
867
|
let fileSize = get(file, 'size')
|
|
289
868
|
|
|
@@ -447,11 +1026,9 @@ function WFtp() {
|
|
|
447
1026
|
|
|
448
1027
|
//ftpLs
|
|
449
1028
|
let fsRemote = await ftpLs(fdRemote)
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
// return v
|
|
454
|
-
// })
|
|
1029
|
+
fsRemote = filter(fsRemote, (v) => {
|
|
1030
|
+
return !v.isFolder
|
|
1031
|
+
})
|
|
455
1032
|
// console.log('fsRemote', fsRemote)
|
|
456
1033
|
|
|
457
1034
|
//check fdLocal
|
|
@@ -624,7 +1201,8 @@ function WFtp() {
|
|
|
624
1201
|
conn: ftpConn,
|
|
625
1202
|
ls: ftpLs,
|
|
626
1203
|
stateFile: ftpStateFile,
|
|
627
|
-
|
|
1204
|
+
isFile: ftpIsFile,
|
|
1205
|
+
isFolder: ftpIsFolder,
|
|
628
1206
|
download: ftpDownload,
|
|
629
1207
|
syncToLocal: ftpSyncToLocal,
|
|
630
1208
|
syncToRemote: ftpSyncToRemote,
|
|
@@ -652,7 +1230,7 @@ export default WFtp
|
|
|
652
1230
|
<br class="clear">
|
|
653
1231
|
|
|
654
1232
|
<footer>
|
|
655
|
-
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.10</a> on
|
|
1233
|
+
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.
|
|
656
1234
|
</footer>
|
|
657
1235
|
|
|
658
1236
|
<script>prettyPrint();</script>
|