UNPKG

w-ftp

Version:

A tool for FTP(FTP, SFTP).

2,908 lines (788 loc) 48.5 kB
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Global - Documentation</title> <script src="scripts/prettify/prettify.js"></script> <script src="scripts/prettify/lang-css.js"></script> <!--[if lt IE 9]> <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script> <![endif]--> <link type="text/css" rel="stylesheet" href="styles/prettify.css"> <link type="text/css" rel="stylesheet" href="styles/jsdoc.css"> <script src="scripts/nav.js" defer></script> <meta name="viewport" content="width=device-width, initial-scale=1.0"> </head> <body> <input type="checkbox" id="nav-trigger" class="nav-trigger" /> <label for="nav-trigger" class="navicon-button x"> <div class="navicon"></div> </label> <label for="nav-trigger" class="overlay"></label> <nav > <h2><a href="index.html">Home</a></h2><h3>Global</h3><ul><li><a href="global.html#WFtp">WFtp</a></li><li><a href="global.html#conn">conn</a></li><li><a href="global.html#cwd">cwd</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#mkdir">mkdir</a></li><li><a href="global.html#pwd">pwd</a></li><li><a href="global.html#quit">quit</a></li><li><a href="global.html#stat">stat</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></ul> </nav> <div id="main"> <h1 class="page-title">Global</h1> <section> <header> <h2> </h2> </header> <article> <div class="container-overview"> <dl class="details"> </dl> </div> <h3 class="subsection-title">Methods</h3> <h4 class="name" id="WFtp"><span class="type-signature"></span>WFtp<span class="signature">(opt<span class="signature-attributes">opt</span>)</span><span class="type-signature"> &rarr; {Object}</span></h4> <dl class="details"> <dt class="tag-description">Description:</dt> <dd class="tag-description"><ul class="dummy"><li><p>操作FTP,包含連線、下載、資料夾內檔案同步下載、上傳、資料夾內檔案同步上傳等功能</p></li></ul></dd> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="WFtp.mjs.html">WFtp.mjs</a>, <a href="WFtp.mjs.html#line678">line 678</a> </li></ul></dd> </dl> <h5 class="h5-examples">Example</h5> <pre class="prettyprint"><code>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 }</code></pre> <h5 class="h5-parameters">Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th>Attributes</th> <th>Default</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>opt</code></td> <td class="type"> <span class="param-type">Object</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="default"> <code>{}</code> </td> <td class="description last"><p>輸入設定物件,預設{}</p> <h6>Properties</h6> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th>Attributes</th> <th>Default</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>transportation</code></td> <td class="type"> <span class="param-type">String</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="default"> <code>'FTP'</code> </td> <td class="description last"><p>輸入傳輸協定字串,可選'FTP'、'SFTP',預設'FTP'</p></td> </tr> <tr> <td class="name"><code>hostname</code></td> <td class="type"> <span class="param-type">String</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="default"> <code>''</code> </td> <td class="description last"><p>輸入hostname字串,預設''</p></td> </tr> <tr> <td class="name"><code>port</code></td> <td class="type"> <span class="param-type">Number</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="default"> <code>21|22</code> </td> <td class="description last"><p>輸入port正整數,當transportation='FTP'預設21,當transportation='SFTP'預設22</p></td> </tr> <tr> <td class="name"><code>username</code></td> <td class="type"> <span class="param-type">String</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="default"> <code>''</code> </td> <td class="description last"><p>輸入帳號字串,預設''</p></td> </tr> <tr> <td class="name"><code>password</code></td> <td class="type"> <span class="param-type">String</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="default"> <code>''</code> </td> <td class="description last"><p>輸入密碼字串,預設''</p></td> </tr> </tbody> </table> </td> </tr> </tbody> </table> <h5 class="h5-returns">Returns:</h5> <div class="param-desc"> <p>回傳FTP操作物件,包含conn、ls、stat、isFile、download、syncToLocal、syncToRemote、upload、quit。</p> </div> <dl class="param-type"> <dt> Type </dt> <dd> <span class="param-type">Object</span> </dd> </dl> <h4 class="name" id="conn"><span class="type-signature type-signature-async">(async) </span>conn<span class="signature">()</span><span class="type-signature"> &rarr; {Promise}</span></h4> <dl class="details"> <dt class="tag-description">Description:</dt> <dd class="tag-description"><ul class="dummy"><li><p>連線至FPT伺服器</p></li></ul></dd> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="WFtp.mjs.html">WFtp.mjs</a>, <a href="WFtp.mjs.html#line39">line 39</a> </li></ul></dd> </dl> <h5 class="h5-examples">Example</h5> <pre class="prettyprint"><code>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) })</code></pre> <h5 class="h5-returns">Returns:</h5> <div class="param-desc"> <p>回傳Promise,resolve回傳成功訊息,reject回傳錯誤訊息</p> </div> <dl class="param-type"> <dt> Type </dt> <dd> <span class="param-type">Promise</span> </dd> </dl> <h4 class="name" id="cwd"><span class="type-signature type-signature-async">(async) </span>cwd<span class="signature">()</span><span class="type-signature"> &rarr; {Promise}</span></h4> <dl class="details"> <dt class="tag-description">Description:</dt> <dd class="tag-description"><ul class="dummy"><li><p>伺服器變更工作路徑資料夾</p></li></ul></dd> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="WFtp.mjs.html">WFtp.mjs</a>, <a href="WFtp.mjs.html#line483">line 483</a> </li></ul></dd> </dl> <h5 class="h5-examples">Example</h5> <pre class="prettyprint"><code>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) })</code></pre> <h5 class="h5-parameters">Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>opt.fpRemote</code></td> <td class="type"> <span class="param-type">String</span> </td> <td class="description last"><p>輸入伺服器上欲指定之工作路徑資料夾字串</p></td> </tr> </tbody> </table> <h5 class="h5-returns">Returns:</h5> <div class="param-desc"> <p>回傳Promise,resolve回傳變更資訊,reject回傳錯誤訊息</p> </div> <dl class="param-type"> <dt> Type </dt> <dd> <span class="param-type">Promise</span> </dd> </dl> <h4 class="name" id="download"><span class="type-signature type-signature-async">(async) </span>download<span class="signature">()</span><span class="type-signature"> &rarr; {Promise}</span></h4> <dl class="details"> <dt class="tag-description">Description:</dt> <dd class="tag-description"><ul class="dummy"><li><p>下載伺服器指定檔案至本機</p></li></ul></dd> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="WFtp.mjs.html">WFtp.mjs</a>, <a href="WFtp.mjs.html#line237">line 237</a> </li></ul></dd> </dl> <h5 class="h5-examples">Example</h5> <pre class="prettyprint"><code>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) })</code></pre> <h5 class="h5-parameters">Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th>Attributes</th> <th>Default</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>opt.fpRemote</code></td> <td class="type"> <span class="param-type">String</span> </td> <td class="attributes"> </td> <td class="default"> </td> <td class="description last"><p>輸入伺服器上指定檔案字串</p></td> </tr> <tr> <td class="name"><code>opt.fpLocal</code></td> <td class="type"> <span class="param-type">String</span> </td> <td class="attributes"> </td> <td class="default"> </td> <td class="description last"><p>輸入本機指定檔案字串</p></td> </tr> <tr> <td class="name"><code>opt.cbProcess</code></td> <td class="type"> <span class="param-type">function</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="default"> <code>null</code> </td> <td class="description last"><p>輸入回調進度函數</p></td> </tr> </tbody> </table> <h5 class="h5-returns">Returns:</h5> <div class="param-desc"> <p>回傳Promise,resolve回傳成功訊息,reject回傳錯誤訊息</p> </div> <dl class="param-type"> <dt> Type </dt> <dd> <span class="param-type">Promise</span> </dd> </dl> <h4 class="name" id="isFile"><span class="type-signature type-signature-async">(async) </span>isFile<span class="signature">()</span><span class="type-signature"> &rarr; {Promise}</span></h4> <dl class="details"> <dt class="tag-description">Description:</dt> <dd class="tag-description"><ul class="dummy"><li><p>確認伺服器指定檔案是否存在</p></li></ul></dd> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="WFtp.mjs.html">WFtp.mjs</a>, <a href="WFtp.mjs.html#line155">line 155</a> </li></ul></dd> </dl> <h5 class="h5-examples">Example</h5> <pre class="prettyprint"><code>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) })</code></pre> <h5 class="h5-parameters">Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>opt.fpRemote</code></td> <td class="type"> <span class="param-type">String</span> </td> <td class="description last"><p>輸入伺服器上指定檔案字串</p></td> </tr> </tbody> </table> <h5 class="h5-returns">Returns:</h5> <div class="param-desc"> <p>回傳Promise,resolve回傳指定檔案是否存在布林值,reject回傳錯誤訊息</p> </div> <dl class="param-type"> <dt> Type </dt> <dd> <span class="param-type">Promise</span> </dd> </dl> <h4 class="name" id="isFolder"><span class="type-signature type-signature-async">(async) </span>isFolder<span class="signature">()</span><span class="type-signature"> &rarr; {Promise}</span></h4> <dl class="details"> <dt class="tag-description">Description:</dt> <dd class="tag-description"><ul class="dummy"><li><p>確認伺服器指定資料夾是否存在</p></li></ul></dd> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="WFtp.mjs.html">WFtp.mjs</a>, <a href="WFtp.mjs.html#line194">line 194</a> </li></ul></dd> </dl> <h5 class="h5-examples">Example</h5> <pre class="prettyprint"><code>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) })</code></pre> <h5 class="h5-parameters">Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>opt.fpRemote</code></td> <td class="type"> <span class="param-type">String</span> </td> <td class="description last"><p>輸入伺服器上指定資料夾字串</p></td> </tr> </tbody> </table> <h5 class="h5-returns">Returns:</h5> <div class="param-desc"> <p>回傳Promise,resolve回傳指定資料夾是否存在布林值,reject回傳錯誤訊息</p> </div> <dl class="param-type"> <dt> Type </dt> <dd> <span class="param-type">Promise</span> </dd> </dl> <h4 class="name" id="ls"><span class="type-signature type-signature-async">(async) </span>ls<span class="signature">()</span><span class="type-signature"> &rarr; {Promise}</span></h4> <dl class="details"> <dt class="tag-description">Description:</dt> <dd class="tag-description"><ul class="dummy"><li><p>遍歷伺服器上指定資料夾內檔案清單資訊</p></li></ul></dd> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="WFtp.mjs.html">WFtp.mjs</a>, <a href="WFtp.mjs.html#line116">line 116</a> </li></ul></dd> </dl> <h5 class="h5-examples">Example</h5> <pre class="prettyprint"><code>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) })</code></pre> <h5 class="h5-parameters">Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>opt.fdRemote</code></td> <td class="type"> <span class="param-type">String</span> </td> <td class="description last"><p>輸入伺服器上指定資料夾字串</p></td> </tr> </tbody> </table> <h5 class="h5-returns">Returns:</h5> <div class="param-desc"> <p>回傳Promise,resolve回傳檔案清單陣列,reject回傳錯誤訊息</p> </div> <dl class="param-type"> <dt> Type </dt> <dd> <span class="param-type">Promise</span> </dd> </dl> <h4 class="name" id="mkdir"><span class="type-signature type-signature-async">(async) </span>mkdir<span class="signature">()</span><span class="type-signature"> &rarr; {Promise}</span></h4> <dl class="details"> <dt class="tag-description">Description:</dt> <dd class="tag-description"><ul class="dummy"><li><p>伺服器創建資料夾</p></li></ul></dd> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="WFtp.mjs.html">WFtp.mjs</a>, <a href="WFtp.mjs.html#line444">line 444</a> </li></ul></dd> </dl> <h5 class="h5-examples">Example</h5> <pre class="prettyprint"><code>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) })</code></pre> <h5 class="h5-parameters">Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>opt.fpRemote</code></td> <td class="type"> <span class="param-type">String</span> </td> <td class="description last"><p>輸入伺服器上待創建資料夾字串</p></td> </tr> </tbody> </table> <h5 class="h5-returns">Returns:</h5> <div class="param-desc"> <p>回傳Promise,resolve回傳創建資訊,reject回傳錯誤訊息</p> </div> <dl class="param-type"> <dt> Type </dt> <dd> <span class="param-type">Promise</span> </dd> </dl> <h4 class="name" id="pwd"><span class="type-signature type-signature-async">(async) </span>pwd<span class="signature">()</span><span class="type-signature"> &rarr; {Promise}</span></h4> <dl class="details"> <dt class="tag-description">Description:</dt> <dd class="tag-description"><ul class="dummy"><li><p>取得伺服器工作路徑資料夾</p></li></ul></dd> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="WFtp.mjs.html">WFtp.mjs</a>, <a href="WFtp.mjs.html#line521">line 521</a> </li></ul></dd> </dl> <h5 class="h5-examples">Example</h5> <pre class="prettyprint"><code>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) })</code></pre> <h5 class="h5-returns">Returns:</h5> <div class="param-desc"> <p>回傳Promise,resolve回傳工作路徑資料夾字串,reject回傳錯誤訊息</p> </div> <dl class="param-type"> <dt> Type </dt> <dd> <span class="param-type">Promise</span> </dd> </dl> <h4 class="name" id="quit"><span class="type-signature type-signature-async">(async) </span>quit<span class="signature">()</span><span class="type-signature"> &rarr; {Promise}</span></h4> <dl class="details"> <dt class="tag-description">Description:</dt> <dd class="tag-description"><ul class="dummy"><li><p>關閉與伺服器連線</p></li></ul></dd> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="WFtp.mjs.html">WFtp.mjs</a>, <a href="WFtp.mjs.html#line76">line 76</a> </li></ul></dd> </dl> <h5 class="h5-examples">Example</h5> <pre class="prettyprint"><code>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) })</code></pre> <h5 class="h5-returns">Returns:</h5> <div class="param-desc"> <p>回傳Promise,resolve回傳成功訊息,reject回傳錯誤訊息</p> </div> <dl class="param-type"> <dt> Type </dt> <dd> <span class="param-type">Promise</span> </dd> </dl> <h4 class="name" id="stat"><span class="type-signature type-signature-async">(async) </span>stat<span class="signature">()</span><span class="type-signature"> &rarr; {Promise}</span></h4> <dl class="details"> <dt class="tag-description">Description:</dt> <dd class="tag-description"><ul class="dummy"><li><p>取得伺服器指定檔案資訊</p></li></ul></dd> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="WFtp.mjs.html">WFtp.mjs</a>, <a href="WFtp.mjs.html#line405">line 405</a> </li></ul></dd> </dl> <h5 class="h5-examples">Example</h5> <pre class="prettyprint"><code>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) })</code></pre> <h5 class="h5-parameters">Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>opt.fpRemote</code></td> <td class="type"> <span class="param-type">String</span> </td> <td class="description last"><p>輸入伺服器上指定檔案字串</p></td> </tr> </tbody> </table> <h5 class="h5-returns">Returns:</h5> <div class="param-desc"> <p>回傳Promise,resolve回傳檔案資訊,reject回傳錯誤訊息</p> </div> <dl class="param-type"> <dt> Type </dt> <dd> <span class="param-type">Promise</span> </dd> </dl> <h4 class="name" id="syncToLocal"><span class="type-signature type-signature-async">(async) </span>syncToLocal<span class="signature">()</span><span class="type-signature"> &rarr; {Promise}</span></h4> <dl class="details"> <dt class="tag-description">Description:</dt> <dd class="tag-description"><ul class="dummy"><li><p>同步伺服器上指定資料夾內檔案至本機</p></li></ul></dd> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="WFtp.mjs.html">WFtp.mjs</a>, <a href="WFtp.mjs.html#line323">line 323</a> </li></ul></dd> </dl> <h5 class="h5-examples">Example</h5> <pre class="prettyprint"><code>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) })</code></pre> <h5 class="h5-parameters">Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th>Attributes</th> <th>Default</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>opt.fdRemote</code></td> <td class="type"> <span class="param-type">String</span> </td> <td class="attributes"> </td> <td class="default"> </td> <td class="description last"><p>輸入伺服器上指定資料夾字串</p></td> </tr> <tr> <td class="name"><code>opt.fdLocal</code></td> <td class="type"> <span class="param-type">String</span> </td> <td class="attributes"> </td> <td class="default"> </td> <td class="description last"><p>輸入本機指定資料夾字串</p></td> </tr> <tr> <td class="name"><code>opt.cbProcess</code></td> <td class="type"> <span class="param-type">function</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="default"> <code>null</code> </td> <td class="description last"><p>輸入回調進度函數</p></td> </tr> </tbody> </table> <h5 class="h5-returns">Returns:</h5> <div class="param-desc"> <p>回傳Promise,resolve回傳成功訊息,reject回傳錯誤訊息</p> </div> <dl class="param-type"> <dt> Type </dt> <dd> <span class="param-type">Promise</span> </dd> </dl> <h4 class="name" id="syncToRemote"><span class="type-signature type-signature-async">(async) </span>syncToRemote<span class="signature">()</span><span class="type-signature"> &rarr; {Promise}</span></h4> <dl class="details"> <dt class="tag-description">Description:</dt> <dd class="tag-description"><ul class="dummy"><li><p>同步本機指定資料夾內檔案至伺服器</p></li></ul></dd> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="WFtp.mjs.html">WFtp.mjs</a>, <a href="WFtp.mjs.html#line366">line 366</a> </li></ul></dd> </dl> <h5 class="h5-examples">Example</h5> <pre class="prettyprint"><code>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) })</code></pre> <h5 class="h5-parameters">Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th>Attributes</th> <th>Default</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>opt.fdLocal</code></td> <td class="type"> <span class="param-type">String</span> </td> <td class="attributes"> </td> <td class="default"> </td> <td class="description last"><p>輸入本機指定資料夾字串</p></td> </tr> <tr> <td class="name"><code>opt.fdRemote</code></td> <td class="type"> <span class="param-type">String</span> </td> <td class="attributes"> </td> <td class="default"> </td> <td class="description last"><p>輸入伺服器上指定資料夾字串</p></td> </tr> <tr> <td class="name"><code>opt.cbProcess</code></td> <td class="type"> <span class="param-type">function</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="default"> <code>null</code> </td> <td class="description last"><p>輸入回調進度函數</p></td> </tr> </tbody> </table> <h5 class="h5-returns">Returns:</h5> <div class="param-desc"> <p>回傳Promise,resolve回傳成功訊息,reject回傳錯誤訊息</p> </div> <dl class="param-type"> <dt> Type </dt> <dd> <span class="param-type">Promise</span> </dd> </dl> <h4 class="name" id="upload"><span class="type-signature type-signature-async">(async) </span>upload<span class="signature">()</span><span class="type-signature"> &rarr; {Promise}</span></h4> <dl class="details"> <dt class="tag-description">Description:</dt> <dd class="tag-description"><ul class="dummy"><li><p>上傳本機指定檔案至伺服器</p></li></ul></dd> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="WFtp.mjs.html">WFtp.mjs</a>, <a href="WFtp.mjs.html#line280">line 280</a> </li></ul></dd> </dl> <h5 class="h5-examples">Example</h5> <pre class="prettyprint"><code>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) })</code></pre> <h5 class="h5-parameters">Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th>Attributes</th> <th>Default</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>opt.fpLocal</code></td> <td class="type"> <span class="param-type">String</span> </td> <td class="attributes"> </td> <td class="default"> </td> <td class="description last"><p>輸入本機指定檔案字串</p></td> </tr> <tr> <td class="name"><code>opt.fpRemote</code></td> <td class="type"> <span class="param-type">String</span> </td> <td class="attributes"> </td> <td class="default"> </td> <td class="description last"><p>輸入伺服器上指定檔案字串</p></td> </tr> <tr> <td class="name"><code>opt.cbProcess</code></td> <td class="type"> <span class="param-type">function</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="default"> <code>null</code> </td> <td class="description last"><p>輸入回調進度函數</p></td> </tr> </tbody> </table> <h5 class="h5-returns">Returns:</h5> <div class="param-desc"> <p>回傳Promise,resolve回傳成功訊息,reject回傳錯誤訊息</p> </div> <dl class="param-type"> <dt> Type </dt> <dd> <span class="param-type">Promise</span> </dd> </dl> </article> </section> </div> <br class="clear"> <footer> Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.2</a> on Sun May 04 2025 21:54:43 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme. </footer> <script>prettyPrint();</script> <script src="scripts/polyfill.js"></script> <script src="scripts/linenumber.js"></script> </body> </html>