UNPKG

sftp-promises

Version:

SFTP Promise wrapper for ssh2 SFTP commands

2,845 lines (677 loc) 31.4 kB
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>JSDoc: Class: SFTPClient</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-tomorrow.css"> <link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css"> </head> <body> <div id="main"> <h1 class="page-title">Class: SFTPClient</h1> <section> <header> <h2><span class="attribs"><span class="type-signature"></span></span>SFTPClient<span class="signature">(config)</span><span class="type-signature"></span></h2> </header> <article> <div class="container-overview"> <h4 class="name" id="SFTPClient"><span class="type-signature"></span>new SFTPClient<span class="signature">(config)</span><span class="type-signature"></span></h4> <div class="description"> Constructor for creating SFTPClient </div> <h5>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>config</code></td> <td class="type"> <span class="param-type">*</span> </td> <td class="description last"></td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="index.js.html">index.js</a>, <a href="index.js.html#line19">line 19</a> </li></ul></dd> </dl> </div> <h3 class="subsection-title">Methods</h3> <h4 class="name" id="createReadStream"><span class="type-signature"></span>createReadStream<span class="signature">()</span><span class="type-signature"></span></h4> <div class="description"> get a readable stream to remote file </div> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="index.js.html">index.js</a>, <a href="index.js.html#line439">line 439</a> </li></ul></dd> </dl> <h4 class="name" id="createWriteStream"><span class="type-signature"></span>createWriteStream<span class="signature">()</span><span class="type-signature"></span></h4> <div class="description"> get a writable stream to remote file </div> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="index.js.html">index.js</a>, <a href="index.js.html#line482">line 482</a> </li></ul></dd> </dl> <h4 class="name" id="get"><span class="type-signature"></span>get<span class="signature">(remotepath, localpath, session<span class="signature-attributes">opt</span>)</span><span class="type-signature"></span></h4> <div class="description"> get remote file and save it locally </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th>Attributes</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>remotepath</code></td> <td class="type"> <span class="param-type">string</span> </td> <td class="attributes"> </td> <td class="description last">path to remote file</td> </tr> <tr> <td class="name"><code>localpath</code></td> <td class="type"> <span class="param-type">string</span> </td> <td class="attributes"> </td> <td class="description last">destination path on local filesystem</td> </tr> <tr> <td class="name"><code>session</code></td> <td class="type"> <span class="param-type">ssh2.Client</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="description last">existing ssh2 connection, optional</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="index.js.html">index.js</a>, <a href="index.js.html#line250">line 250</a> </li></ul></dd> </dl> <h4 class="name" id="getBuffer"><span class="type-signature"></span>getBuffer<span class="signature">(path, session<span class="signature-attributes">opt</span>)</span><span class="type-signature"> &rarr; {Promise}</span></h4> <div class="description"> get remote file contents into a Buffer </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th>Attributes</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>path</code></td> <td class="type"> <span class="param-type">string</span> </td> <td class="attributes"> </td> <td class="description last">on filesystem to stat</td> </tr> <tr> <td class="name"><code>session</code></td> <td class="type"> <span class="param-type">ssh2.Client</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="description last">existing ssh2 connection, optional</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="index.js.html">index.js</a>, <a href="index.js.html#line181">line 181</a> </li></ul></dd> </dl> <h5>Returns:</h5> <div class="param-desc"> Promise with Buffer on resolve </div> <dl> <dt> Type </dt> <dd> <span class="param-type">Promise</span> </dd> </dl> <h4 class="name" id="getStream"><span class="type-signature"></span>getStream<span class="signature">()</span><span class="type-signature"></span></h4> <div class="description"> stream file contents from remote file </div> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="index.js.html">index.js</a>, <a href="index.js.html#line369">line 369</a> </li></ul></dd> </dl> <h4 class="name" id="ls"><span class="type-signature"></span>ls<span class="signature">(path, session<span class="signature-attributes">opt</span>)</span><span class="type-signature"> &rarr; {Promise}</span></h4> <div class="description"> unix ls -l style return </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th>Attributes</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>path</code></td> <td class="type"> <span class="param-type">string</span> </td> <td class="attributes"> </td> <td class="description last">on filesystem to stat</td> </tr> <tr> <td class="name"><code>session</code></td> <td class="type"> <span class="param-type">ssh2.Client</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="description last">existing ssh2 connection, optional</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="index.js.html">index.js</a>, <a href="index.js.html#line118">line 118</a> </li></ul></dd> </dl> <h5>Returns:</h5> <div class="param-desc"> Promise with object describing path </div> <dl> <dt> Type </dt> <dd> <span class="param-type">Promise</span> </dd> </dl> <h4 class="name" id="mkdir"><span class="type-signature"></span>mkdir<span class="signature">(path, session<span class="signature-attributes">opt</span>)</span><span class="type-signature"></span></h4> <div class="description"> makes a directory </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th>Attributes</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>path</code></td> <td class="type"> <span class="param-type">string</span> </td> <td class="attributes"> </td> <td class="description last">remote directory to be created</td> </tr> <tr> <td class="name"><code>session</code></td> <td class="type"> <span class="param-type">ssh2.Client</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="description last">existing ssh2 connection, optional</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="index.js.html">index.js</a>, <a href="index.js.html#line347">line 347</a> </li></ul></dd> </dl> <h4 class="name" id="mv"><span class="type-signature"></span>mv<span class="signature">(source, destination, session<span class="signature-attributes">opt</span>)</span><span class="type-signature"></span></h4> <div class="description"> move remote file from one spot to another </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th>Attributes</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>source</code></td> <td class="type"> <span class="param-type">string</span> </td> <td class="attributes"> </td> <td class="description last">remote filesystem source path</td> </tr> <tr> <td class="name"><code>destination</code></td> <td class="type"> <span class="param-type">string</span> </td> <td class="attributes"> </td> <td class="description last">remote filesystem desitnation path</td> </tr> <tr> <td class="name"><code>session</code></td> <td class="type"> <span class="param-type">ssh2.Client</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="description last">existing ssh2 connection, optional</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="index.js.html">index.js</a>, <a href="index.js.html#line309">line 309</a> </li></ul></dd> </dl> <h4 class="name" id="put"><span class="type-signature"></span>put<span class="signature">(localpath, remotepath, session<span class="signature-attributes">opt</span>)</span><span class="type-signature"></span></h4> <div class="description"> put local file in remote path </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th>Attributes</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>localpath</code></td> <td class="type"> <span class="param-type">string</span> </td> <td class="attributes"> </td> <td class="description last">path to local file</td> </tr> <tr> <td class="name"><code>remotepath</code></td> <td class="type"> <span class="param-type">string</span> </td> <td class="attributes"> </td> <td class="description last">destination path on remote filesystem</td> </tr> <tr> <td class="name"><code>session</code></td> <td class="type"> <span class="param-type">ssh2.Client</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="description last">existing ssh2 connection, optional</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="index.js.html">index.js</a>, <a href="index.js.html#line270">line 270</a> </li></ul></dd> </dl> <h4 class="name" id="putBuffer"><span class="type-signature"></span>putBuffer<span class="signature">(buffer, path, session<span class="signature-attributes">opt</span>)</span><span class="type-signature"> &rarr; {Promise}</span></h4> <div class="description"> put buffer to remote file </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th>Attributes</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>buffer</code></td> <td class="type"> <span class="param-type">Buffer</span> </td> <td class="attributes"> </td> <td class="description last">Buffer containing file contents</td> </tr> <tr> <td class="name"><code>path</code></td> <td class="type"> <span class="param-type">string</span> </td> <td class="attributes"> </td> <td class="description last">on filesystem to stat</td> </tr> <tr> <td class="name"><code>session</code></td> <td class="type"> <span class="param-type">ssh2.Client</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="description last">existing ssh2 connection, optional</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="index.js.html">index.js</a>, <a href="index.js.html#line224">line 224</a> </li></ul></dd> </dl> <h5>Returns:</h5> <div class="param-desc"> Promise with boolean true if tranfer was successful </div> <dl> <dt> Type </dt> <dd> <span class="param-type">Promise</span> </dd> </dl> <h4 class="name" id="putStream"><span class="type-signature"></span>putStream<span class="signature">()</span><span class="type-signature"></span></h4> <div class="description"> stream file contents from local file </div> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="index.js.html">index.js</a>, <a href="index.js.html#line407">line 407</a> </li></ul></dd> </dl> <h4 class="name" id="rm"><span class="type-signature"></span>rm<span class="signature">(path, session<span class="signature-attributes">opt</span>)</span><span class="type-signature"></span></h4> <div class="description"> remove remote file </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th>Attributes</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>path</code></td> <td class="type"> <span class="param-type">string</span> </td> <td class="attributes"> </td> <td class="description last">remote file to remove</td> </tr> <tr> <td class="name"><code>session</code></td> <td class="type"> <span class="param-type">ssh2.Client</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="description last">existing ssh2 connection, optional</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="index.js.html">index.js</a>, <a href="index.js.html#line289">line 289</a> </li></ul></dd> </dl> <h4 class="name" id="rmdir"><span class="type-signature"></span>rmdir<span class="signature">(path, session<span class="signature-attributes">opt</span>)</span><span class="type-signature"></span></h4> <div class="description"> removes and empty directory </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th>Attributes</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>path</code></td> <td class="type"> <span class="param-type">string</span> </td> <td class="attributes"> </td> <td class="description last">remote directroy to remove</td> </tr> <tr> <td class="name"><code>session</code></td> <td class="type"> <span class="param-type">ssh2.Client</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="description last">existing ssh2 connection, optional</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="index.js.html">index.js</a>, <a href="index.js.html#line328">line 328</a> </li></ul></dd> </dl> <h4 class="name" id="session"><span class="type-signature"></span>session<span class="signature">()</span><span class="type-signature"> &rarr; {Promise}</span></h4> <div class="description"> creates a new ssh2 session, short cut for sshClient = require('ssh2')sshClient session = new SFTPClient(config) </div> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="index.js.html">index.js</a>, <a href="index.js.html#line90">line 90</a> </li></ul></dd> </dl> <h5>Returns:</h5> <div class="param-desc"> returns a Promse with an ssh2 connection object if resovled </div> <dl> <dt> Type </dt> <dd> <span class="param-type">Promise</span> </dd> </dl> <h4 class="name" id="sftpCmd"><span class="type-signature"></span>sftpCmd<span class="signature">(cmdCB, session<span class="signature-attributes">opt</span>)</span><span class="type-signature"></span></h4> <div class="description"> Creates connection and promise wrapper for sftp commands </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th>Attributes</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>cmdCB</code></td> <td class="type"> <span class="param-type">callback</span> </td> <td class="attributes"> </td> <td class="description last">callback for sftp, takes connection, reject and resolve cmb_cb(con, reject,resolve)</td> </tr> <tr> <td class="name"><code>session</code></td> <td class="type"> <span class="param-type">ssh2.Client</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="description last">existing ssh2 connection, optional</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="index.js.html">index.js</a>, <a href="index.js.html#line36">line 36</a> </li></ul></dd> </dl> <h4 class="name" id="stat"><span class="type-signature"></span>stat<span class="signature">(path, session<span class="signature-attributes">opt</span>)</span><span class="type-signature"> &rarr; {Promise}</span></h4> <div class="description"> stat a file or directory </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th>Attributes</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>path</code></td> <td class="type"> <span class="param-type">string</span> </td> <td class="attributes"> </td> <td class="description last">on filesystem to stat</td> </tr> <tr> <td class="name"><code>session</code></td> <td class="type"> <span class="param-type">ssh2.Client</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="description last">existing ssh2 connection, optional</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="index.js.html">index.js</a>, <a href="index.js.html#line150">line 150</a> </li></ul></dd> </dl> <h5>Returns:</h5> <div class="param-desc"> Promise with object describing path </div> <dl> <dt> Type </dt> <dd> <span class="param-type">Promise</span> </dd> </dl> </article> </section> </div> <nav> <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="SFTPClient.html">SFTPClient</a></li></ul> </nav> <br class="clear"> <footer> Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Thu May 24 2018 15:49:32 GMT-0600 (MDT) </footer> <script> prettyPrint(); </script> <script src="scripts/linenumber.js"> </script> </body> </html>