Methods
WFtp(optopt) → {Object}
Example
import WFtp from './src/WFtp.mjs'
async function test_dw() {
let r
let ftp = WFtp({
hostname: `{hostname}`,
port: `{port}`,
username: `{username}`,
password: `{password}`,
})
// console.log('ftp', ftp)
await ftp.conn()
async function core() {
let fps = await ftp.ls('.')
console.log('ftp.ls', fps[0], fps.length)
r = await ftp.download('./DECL_20210805055044.csv', './_test_download_client/DECL_20210805055044.csv', (p) => {
console.log('ftp.download p', p.name, p.progress)
})
console.log('ftp.download', r)
r = await ftp.syncToLocal('.', './_test_download_client', (p) => {
console.log('ftp.syncToLocal p', p.name, p.progress)
})
console.log('ftp.syncToLocal', r)
}
await core()
.catch((err) => {
console.log(err)
})
r = await ftp.quit()
console.log('ftp.quit', r)
}
test_dw()
.catch((err) => {
console.log(err)
})
// ftp.ls {
// name: 'DECL_202108.csv',
// type: 0,
// time: 1658302140000,
// size: '218690',
// owner: 'ftp',
// group: 'ftp',
// userPermissions: { read: true, write: true, exec: false },
// groupPermissions: { read: true, write: true, exec: false },
// otherPermissions: { read: true, write: true, exec: false }
// } 74
// ftp.download p DECL_20210805055044.csv 4.7320871554333515
// ftp.download p DECL_20210805055044.csv 9.464174310866703
// ftp.download p DECL_20210805055044.csv 14.196261466300053
// ftp.download p DECL_20210805055044.csv 18.928348621733406
// ftp.download p DECL_20210805055044.csv 23.660435777166754
// ftp.download p DECL_20210805055044.csv 28.392522932600105
// ftp.download p DECL_20210805055044.csv 33.12461008803346
// ftp.download p DECL_20210805055044.csv 37.85669724346681
// ftp.download p DECL_20210805055044.csv 42.58878439890016
// ftp.download p DECL_20210805055044.csv 47.32087155433351
// ftp.download p DECL_20210805055044.csv 52.05295870976686
// ftp.download p DECL_20210805055044.csv 56.78504586520021
// ftp.download p DECL_20210805055044.csv 61.517133020633565
// ftp.download p DECL_20210805055044.csv 66.24922017606691
// ftp.download p DECL_20210805055044.csv 70.98130733150026
// ftp.download p DECL_20210805055044.csv 75.71339448693362
// ftp.download p DECL_20210805055044.csv 80.44548164236697
// ftp.download p DECL_20210805055044.csv 85.17756879780032
// ftp.download p DECL_20210805055044.csv 89.90965595323367
// ftp.download p DECL_20210805055044.csv 94.64174310866701
// ftp.download p DECL_20210805055044.csv 99.37383026410038
// ftp.download p DECL_20210805055044.csv 100
// ftp.download ok
// ftp.syncToLocal { num: 0, files: [] }
// ftp.quit { code: 221, text: '221 Goodbye.', isMark: false, isError: false }
async function test_up() {
let r
let ftp = WFtp()
// console.log('ftp', ftp)
await ftp.conn({
hostname: `{hostname}`,
port: `{port}`,
username: `{username}`,
password: `{password}`,
})
async function core() {
let fps = await ftp.ls('.')
console.log('ftp.ls', fps[0], fps.length)
r = await ftp.upload('./_test_upload_client/DECL_20210805055044.csv', './DECL_20210805055044.csv', (p) => {
console.log('ftp.upload p', p.name, p.progress)
})
console.log('ftp.upload', r)
r = await ftp.syncToRemote('./_test_upload_client', '.', (p) => {
console.log('ftp.syncToRemote p', p.name, p.progress)
})
console.log('ftp.syncToRemote', r)
}
await core()
.catch((err) => {
console.log(err)
})
r = await ftp.quit()
console.log('ftp.quit', r)
}
test_up()
.catch((err) => {
console.log(err)
})
// ftp.ls {
// name: 'DECL_202108.csv',
// type: 0,
// time: 1658366760000,
// size: '218690',
// owner: 'ftp',
// group: 'ftp',
// userPermissions: { read: true, write: true, exec: false },
// groupPermissions: { read: true, write: true, exec: false },
// otherPermissions: { read: true, write: true, exec: false }
// } 73
// ftp.upload p DECL_20210805055044.csv 75.71339448693362
// ftp.upload p DECL_20210805055044.csv 100
// ftp.upload ok
// ftp.syncToRemote { num: 0, files: [] }
// ftp.quit { code: 221, text: '221 Goodbye.', isMark: false, isError: false }
Parameters:
Name | Type | Attributes | Default | Description | ||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
opt |
Object |
<optional> |
{}
|
輸入設定物件,預設{} Properties
|
Returns:
回傳FTP操作物件,包含conn、ls、stat、isFile、download、syncToLocal、syncToRemote、upload、quit。
- Type
- Object
(async) conn() → {Promise}
Example
import WFtp from './src/WFtp.mjs'
async function test() {
let r
let ftp = WFtp({
transportation: 'FTP', //'FTP', 'SFTP'
hostname: st.hostname,
port: st.port,
username: st.username,
password: st.password,
})
// console.log('ftp', ftp)
await ftp.conn()
//actions
r = await ftp.quit()
console.log('ftp.quit', r)
}
test()
.catch((err) => {
console.log(err)
})
Returns:
回傳Promise,resolve回傳成功訊息,reject回傳錯誤訊息
- Type
- Promise
(async) cwd() → {Promise}
Example
import WFtp from './src/WFtp.mjs'
async function test() {
let r
let ftp = WFtp({
transportation: 'FTP', //'FTP', 'SFTP'
hostname: st.hostname,
port: st.port,
username: st.username,
password: st.password,
})
// console.log('ftp', ftp)
await ftp.conn()
r = await ftp.cwd('./_test_upload_client')
console.log('ftp.cwd', r)
r = await ftp.quit()
console.log('ftp.quit', r)
}
test()
.catch((err) => {
console.log(err)
})
Parameters:
Name | Type | Description |
---|---|---|
opt.fpRemote |
String | 輸入伺服器上欲指定之工作路徑資料夾字串 |
Returns:
回傳Promise,resolve回傳變更資訊,reject回傳錯誤訊息
- Type
- Promise
(async) download() → {Promise}
Example
import WFtp from './src/WFtp.mjs'
async function test() {
let r
let ftp = WFtp({
transportation: 'FTP', //'FTP', 'SFTP'
hostname: st.hostname,
port: st.port,
username: st.username,
password: st.password,
})
// console.log('ftp', ftp)
await ftp.conn()
r = await ftp.download('./DECL_20210805055044.csv', './_test_download_client/DECL_20210805055044.csv', (p) => {
console.log('ftp.download p', p.name, p.progress)
})
console.log('ftp.download', r)
r = await ftp.quit()
console.log('ftp.quit', r)
}
test()
.catch((err) => {
console.log(err)
})
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
opt.fpRemote |
String | 輸入伺服器上指定檔案字串 |
||
opt.fpLocal |
String | 輸入本機指定檔案字串 |
||
opt.cbProcess |
function |
<optional> |
null
|
輸入回調進度函數 |
Returns:
回傳Promise,resolve回傳成功訊息,reject回傳錯誤訊息
- Type
- Promise
(async) isFile() → {Promise}
Example
import WFtp from './src/WFtp.mjs'
async function test() {
let r
let ftp = WFtp({
transportation: 'FTP', //'FTP', 'SFTP'
hostname: st.hostname,
port: st.port,
username: st.username,
password: st.password,
})
// console.log('ftp', ftp)
await ftp.conn()
r = await ftp.isFile('./_test_upload_client/DECL_20210805055044.csv')
console.log('ftp.isFile', r)
r = await ftp.quit()
console.log('ftp.quit', r)
}
test()
.catch((err) => {
console.log(err)
})
Parameters:
Name | Type | Description |
---|---|---|
opt.fpRemote |
String | 輸入伺服器上指定檔案字串 |
Returns:
回傳Promise,resolve回傳指定檔案是否存在布林值,reject回傳錯誤訊息
- Type
- Promise
(async) isFolder() → {Promise}
Example
import WFtp from './src/WFtp.mjs'
async function test() {
let r
let ftp = WFtp({
transportation: 'FTP', //'FTP', 'SFTP'
hostname: st.hostname,
port: st.port,
username: st.username,
password: st.password,
})
// console.log('ftp', ftp)
await ftp.conn()
r = await ftp.isFolder('./_test_upload_client')
console.log('ftp.isFolder', r)
r = await ftp.quit()
console.log('ftp.quit', r)
}
test()
.catch((err) => {
console.log(err)
})
Parameters:
Name | Type | Description |
---|---|---|
opt.fpRemote |
String | 輸入伺服器上指定資料夾字串 |
Returns:
回傳Promise,resolve回傳指定資料夾是否存在布林值,reject回傳錯誤訊息
- Type
- Promise
(async) ls() → {Promise}
Example
import WFtp from './src/WFtp.mjs'
async function test() {
let r
let ftp = WFtp({
transportation: 'FTP', //'FTP', 'SFTP'
hostname: st.hostname,
port: st.port,
username: st.username,
password: st.password,
})
// console.log('ftp', ftp)
await ftp.conn()
let fps = await ftp.ls('.')
console.log('ftp.ls', fps[0], fps.length)
r = await ftp.quit()
console.log('ftp.quit', r)
}
test()
.catch((err) => {
console.log(err)
})
Parameters:
Name | Type | Description |
---|---|---|
opt.fdRemote |
String | 輸入伺服器上指定資料夾字串 |
Returns:
回傳Promise,resolve回傳檔案清單陣列,reject回傳錯誤訊息
- Type
- Promise
(async) mkdir() → {Promise}
Example
import WFtp from './src/WFtp.mjs'
async function test() {
let r
let ftp = WFtp({
transportation: 'FTP', //'FTP', 'SFTP'
hostname: st.hostname,
port: st.port,
username: st.username,
password: st.password,
})
// console.log('ftp', ftp)
await ftp.conn()
r = await ftp.mkdir('./_test_upload_client')
console.log('ftp.mkdir', r)
r = await ftp.quit()
console.log('ftp.quit', r)
}
test()
.catch((err) => {
console.log(err)
})
Parameters:
Name | Type | Description |
---|---|---|
opt.fpRemote |
String | 輸入伺服器上待創建資料夾字串 |
Returns:
回傳Promise,resolve回傳創建資訊,reject回傳錯誤訊息
- Type
- Promise
(async) pwd() → {Promise}
Example
import WFtp from './src/WFtp.mjs'
async function test() {
let r
let ftp = WFtp({
transportation: 'FTP', //'FTP', 'SFTP'
hostname: st.hostname,
port: st.port,
username: st.username,
password: st.password,
})
// console.log('ftp', ftp)
await ftp.conn()
r = await ftp.pwd()
console.log('ftp.pwd', r)
r = await ftp.quit()
console.log('ftp.quit', r)
}
test()
.catch((err) => {
console.log(err)
})
Returns:
回傳Promise,resolve回傳工作路徑資料夾字串,reject回傳錯誤訊息
- Type
- Promise
(async) quit() → {Promise}
Example
import WFtp from './src/WFtp.mjs'
async function test() {
let r
let ftp = WFtp({
transportation: 'FTP', //'FTP', 'SFTP'
hostname: st.hostname,
port: st.port,
username: st.username,
password: st.password,
})
// console.log('ftp', ftp)
await ftp.conn()
//actions
r = await ftp.quit()
console.log('ftp.quit', r)
}
test()
.catch((err) => {
console.log(err)
})
Returns:
回傳Promise,resolve回傳成功訊息,reject回傳錯誤訊息
- Type
- Promise
(async) stat() → {Promise}
Example
import WFtp from './src/WFtp.mjs'
async function test() {
let r
let ftp = WFtp({
transportation: 'FTP', //'FTP', 'SFTP'
hostname: st.hostname,
port: st.port,
username: st.username,
password: st.password,
})
// console.log('ftp', ftp)
await ftp.conn()
r = await ftp.stat('./_test_upload_client/DECL_20210805055044.csv')
console.log('ftp.stat', r)
r = await ftp.quit()
console.log('ftp.quit', r)
}
test()
.catch((err) => {
console.log(err)
})
Parameters:
Name | Type | Description |
---|---|---|
opt.fpRemote |
String | 輸入伺服器上指定檔案字串 |
Returns:
回傳Promise,resolve回傳檔案資訊,reject回傳錯誤訊息
- Type
- Promise
(async) syncToLocal() → {Promise}
Example
import WFtp from './src/WFtp.mjs'
async function test() {
let r
let ftp = WFtp({
transportation: 'FTP', //'FTP', 'SFTP'
hostname: st.hostname,
port: st.port,
username: st.username,
password: st.password,
})
// console.log('ftp', ftp)
await ftp.conn()
r = await ftp.syncToLocal('.', './_test_download_client', (p) => {
console.log('ftp.syncToLocal p', p.name, p.progress)
})
console.log('ftp.syncToLocal', r)
r = await ftp.quit()
console.log('ftp.quit', r)
}
test()
.catch((err) => {
console.log(err)
})
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
opt.fdRemote |
String | 輸入伺服器上指定資料夾字串 |
||
opt.fdLocal |
String | 輸入本機指定資料夾字串 |
||
opt.cbProcess |
function |
<optional> |
null
|
輸入回調進度函數 |
Returns:
回傳Promise,resolve回傳成功訊息,reject回傳錯誤訊息
- Type
- Promise
(async) syncToRemote() → {Promise}
Example
import WFtp from './src/WFtp.mjs'
async function test() {
let r
let ftp = WFtp({
transportation: 'FTP', //'FTP', 'SFTP'
hostname: st.hostname,
port: st.port,
username: st.username,
password: st.password,
})
// console.log('ftp', ftp)
await ftp.conn()
r = await ftp.syncToRemote('./_test_upload_client', '.', (p) => {
console.log('ftp.syncToRemote p', p.name, p.progress)
})
console.log('ftp.syncToRemote', r)
r = await ftp.quit()
console.log('ftp.quit', r)
}
test()
.catch((err) => {
console.log(err)
})
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
opt.fdLocal |
String | 輸入本機指定資料夾字串 |
||
opt.fdRemote |
String | 輸入伺服器上指定資料夾字串 |
||
opt.cbProcess |
function |
<optional> |
null
|
輸入回調進度函數 |
Returns:
回傳Promise,resolve回傳成功訊息,reject回傳錯誤訊息
- Type
- Promise
(async) upload() → {Promise}
Example
import WFtp from './src/WFtp.mjs'
async function test() {
let r
let ftp = WFtp({
transportation: 'FTP', //'FTP', 'SFTP'
hostname: st.hostname,
port: st.port,
username: st.username,
password: st.password,
})
// console.log('ftp', ftp)
await ftp.conn()
r = await ftp.upload('./_test_upload_client/DECL_20210805055044.csv', './DECL_20210805055044.csv', (p) => {
console.log('ftp.upload p', p.name, p.progress)
})
console.log('ftp.upload', r)
r = await ftp.quit()
console.log('ftp.quit', r)
}
test()
.catch((err) => {
console.log(err)
})
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
opt.fpLocal |
String | 輸入本機指定檔案字串 |
||
opt.fpRemote |
String | 輸入伺服器上指定檔案字串 |
||
opt.cbProcess |
function |
<optional> |
null
|
輸入回調進度函數 |
Returns:
回傳Promise,resolve回傳成功訊息,reject回傳錯誤訊息
- Type
- Promise