first commit
This commit is contained in:
3
build/node_modules/sftp-promises/.eslintrc
generated
vendored
Normal file
3
build/node_modules/sftp-promises/.eslintrc
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"extends": "standard"
|
||||
}
|
||||
29
build/node_modules/sftp-promises/.npmignore
generated
vendored
Normal file
29
build/node_modules/sftp-promises/.npmignore
generated
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
|
||||
# Runtime data
|
||||
pids
|
||||
*.pid
|
||||
*.seed
|
||||
|
||||
# Directory for instrumented libs generated by jscoverage/JSCover
|
||||
lib-cov
|
||||
|
||||
# Coverage directory used by tools like istanbul
|
||||
coverage
|
||||
|
||||
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
|
||||
.grunt
|
||||
|
||||
# node-waf configuration
|
||||
.lock-wscript
|
||||
|
||||
# Compiled binary addons (http://nodejs.org/api/addons.html)
|
||||
build/Release
|
||||
|
||||
# Dependency directory
|
||||
# https://docs.npmjs.com/misc/faq#should-i-check-my-node-modules-folder-into-git
|
||||
node_modules
|
||||
|
||||
28
build/node_modules/sftp-promises/LICENSE
generated
vendored
Normal file
28
build/node_modules/sftp-promises/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
Copyright (c) 2015, Dave Sanderson
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
* Neither the name of sftp-promises nor the names of its
|
||||
contributors may be used to endorse or promote products derived from
|
||||
this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
64
build/node_modules/sftp-promises/README.md
generated
vendored
Normal file
64
build/node_modules/sftp-promises/README.md
generated
vendored
Normal file
@@ -0,0 +1,64 @@
|
||||
# sftp-promises
|
||||
|
||||
[](https://npmjs.org/package/sftp-promises)[](https://coveralls.io/github/brokenbot/sftp-promises?branch=master)
|
||||
|
||||
>SFTP Promise Wrapper for ssh2
|
||||
|
||||
Support basic SFTP transaction with promises, specifically for fronting SFTP with a web based API using something like Koa
|
||||
|
||||
### Warning
|
||||
Each request will create a new conneciton and close it when finished, this is by design as its intended to be used in stateless web applications. As such care should exercised when using on high traffic systems to avoid too many connections to SFTP server and general connection overhead.
|
||||
|
||||
### Streams
|
||||
The current streams implementation requires supplying either readable or writable streams and do not return promises with streams like the getBuffer method. This is to support non-presistent connections which would drop if a stream was returned on the promise resolve.
|
||||
|
||||
# Usage
|
||||
_**One connection per call**_
|
||||
|
||||
|
||||
```javascript
|
||||
var config = {host: 'localhost', username: 'user', password: 'pass' };
|
||||
var SFTPClient = require('sftp-promises');
|
||||
var sftp = new SFTPClient(config);
|
||||
|
||||
sftp.ls('~/').then(function(list) { console.log(list) })
|
||||
```
|
||||
|
||||
_**Persistent Session calls (Experimental)**_
|
||||
|
||||
```javascript
|
||||
var config = {host: 'localhost', username: 'user', password: 'pass' };
|
||||
var SFTPClient = require('sftp-promises');
|
||||
var sftp = new SFTPClient();
|
||||
|
||||
// get session
|
||||
var session = sftp.session(config).then(function(ftpSession) { session = ftpSession })
|
||||
...code to ensure session is ready...
|
||||
sftp.ls('~/', session).then(function(list) { console.log(list) })
|
||||
|
||||
// close socket
|
||||
session.end()
|
||||
```
|
||||
|
||||
config options are the same as [ssh2](https://github.com/mscdex/ssh2) config options.
|
||||
|
||||
# Supported calls
|
||||
> All calls take an optional ssh2 Connction object as the final arguement for using persistent session.
|
||||
|
||||
**sftp.stat(\<string>remote\_path, [ssh2.Connection]session)** returns a promise with on object containing path attributes
|
||||
**sftp.ls(\<string>remote\_path, [ssh2.Connection]session)** returns a promise with an object descibing the path
|
||||
**sftp.getBuffer(\<string>remote\_path, [ssh2.Connection]session)** returns a promise with a buffer containing the file contents
|
||||
**sftp.putBuffer(\<Buffer>data, \<string>remote\_path, [ssh2.Connection]session)** returns a promise with a boolean, true if successful
|
||||
**sftp.get(\<string>remote\_path, \<string>local\_path, [ssh2.Connection]session)** returns a promise with a boolean, true if successful
|
||||
**sftp.put(\<string>local\_path, \<string>remote\_path, [ssh2.Connection]session)** returns a promise with a boolean, true if successful
|
||||
**sftp.rm(\<string>location, [ssh2.Connection]session)** returns a promise with a boolean, true if successful
|
||||
**sftp.mv(\<string>src, \<string>dest, [ssh2.Connection]session)** returns a promise with a boolean, true if successful
|
||||
**sftp.mkdir(\<string>path, [ssh2.Connection]session)** returns a promise with a boolean, true if successful
|
||||
**sftp.rmdir(\<string>path, [ssh2.Connection]session)** returns a promise with a boolean, true if successful
|
||||
**sftp.getStream(\<string>path, <writableStream>writableStream, [ssh2.Connection]session)** returns a promise with a boolean, true if stream write completed
|
||||
**sftp.putStream(\<string>path, <writableStream>writableStream, [ssh2.Connection]session)** returns a promise with a boolean, true is stream write completed
|
||||
|
||||
# Planned Features/Updates
|
||||
* have test rely on ssh2.server instead of local ssh server
|
||||
|
||||
|
||||
489
build/node_modules/sftp-promises/index.js
generated
vendored
Normal file
489
build/node_modules/sftp-promises/index.js
generated
vendored
Normal file
@@ -0,0 +1,489 @@
|
||||
var Client = require('ssh2').Client
|
||||
|
||||
var statToAttrs = function (stats) {
|
||||
var attrs = {}
|
||||
for (var attr in stats) {
|
||||
if (stats.hasOwnProperty(attr)) {
|
||||
attrs[attr] = stats[attr]
|
||||
}
|
||||
}
|
||||
return attrs
|
||||
}
|
||||
|
||||
function SFTPClient (config) {
|
||||
if (!(this instanceof SFTPClient)) {
|
||||
return new SFTPClient(config)
|
||||
}
|
||||
|
||||
this.config = config || {}
|
||||
}
|
||||
|
||||
SFTPClient.prototype.MODES = require('ssh2').SFTP_OPEN_MODE
|
||||
SFTPClient.prototype.CODES = require('ssh2').SFTP_STATUS_CODE
|
||||
|
||||
/**
|
||||
* Creates connection and promise wrapper for sftp commands
|
||||
*
|
||||
* @param {callback} cmdCB - callback for sftp, takes connection, reject and resolve cmb_cb(con, reject,resolve)
|
||||
* @param {ssh2.Client} [session] - existing ssh2 connection, optional
|
||||
*/
|
||||
SFTPClient.prototype.sftpCmd = function sftpCmd (cmdCB, session) {
|
||||
var self = this
|
||||
session = session || false
|
||||
// setup connection
|
||||
var conn
|
||||
if (session) {
|
||||
conn = session
|
||||
} else {
|
||||
conn = new Client()
|
||||
}
|
||||
|
||||
// reject promise handler
|
||||
var rejected = function (err) {
|
||||
handleConn()
|
||||
return Promise.reject(err)
|
||||
}
|
||||
|
||||
// resolve promise handler
|
||||
var resolved = function (val) {
|
||||
handleConn()
|
||||
return Promise.resolve(val)
|
||||
}
|
||||
|
||||
// handle persisten connection
|
||||
var handleConn = function (retPromise) {
|
||||
if (!session) {
|
||||
conn.end()
|
||||
conn.destroy()
|
||||
}
|
||||
return retPromise
|
||||
}
|
||||
|
||||
return new Promise(function (resolve, reject) {
|
||||
if (session) {
|
||||
conn.sftp(cmdCB(resolve, reject))
|
||||
} else {
|
||||
conn.on('ready', function () {
|
||||
conn.sftp(cmdCB(resolve, reject))
|
||||
})
|
||||
conn.on('error', function (err) {
|
||||
reject(err)
|
||||
})
|
||||
conn.connect(self.config)
|
||||
}
|
||||
// handle the persistent connection regardless of how promise fairs
|
||||
}).then(resolved, rejected)
|
||||
}
|
||||
|
||||
/**
|
||||
* creates a new ssh2 session, short cut for
|
||||
* sshClient = require('ssh2')sshClient
|
||||
* session = new SFTPClient(config)
|
||||
*
|
||||
* @params {Object} config - valid ssh2 config
|
||||
* @return {Promise} returns a Promse with an ssh2 connection object if resovled
|
||||
*/
|
||||
SFTPClient.prototype.session = function session (conf) {
|
||||
return new Promise(function (resolve, reject) {
|
||||
var conn = new Client()
|
||||
conn.on('ready', function () {
|
||||
conn.removeAllListeners()
|
||||
resolve(conn)
|
||||
})
|
||||
.on('error', function (err) {
|
||||
reject(err)
|
||||
})
|
||||
try {
|
||||
conn.connect(conf)
|
||||
} catch (err) {
|
||||
reject(err)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* unix ls -l style return
|
||||
*
|
||||
* @param {string} path - on filesystem to stat
|
||||
* @param {ssh2.Client} [session] - existing ssh2 connection, optional
|
||||
* @return {Promise} Promise with object describing path
|
||||
*/
|
||||
SFTPClient.prototype.ls = function ls (location, session) {
|
||||
// create the lsCmd callback for this.sftpCmd
|
||||
var lsCmd = function (resolve, reject) {
|
||||
return function (err, sftp) {
|
||||
if (err) {
|
||||
return reject(err)
|
||||
}
|
||||
sftp.stat(location, function (err, stat) {
|
||||
if (err) {
|
||||
return reject(err)
|
||||
}
|
||||
var attrs = statToAttrs(stat)
|
||||
if (stat.isDirectory()) {
|
||||
sftp.readdir(location, function (err, list) {
|
||||
if (err) { reject(err) }
|
||||
resolve({ path: location, type: 'directory', attrs: attrs, entries: list })
|
||||
})
|
||||
} else if (stat.isFile()) {
|
||||
resolve({ path: location, type: 'file', attrs: attrs })
|
||||
} else {
|
||||
resolve({ path: location, type: 'other', attrs: attrs })
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
// return the value of the command
|
||||
return this.sftpCmd(lsCmd, session)
|
||||
}
|
||||
|
||||
/**
|
||||
* stat a file or directory
|
||||
*
|
||||
* @param {string} path - on filesystem to stat
|
||||
* @param {ssh2.Client} [session] - existing ssh2 connection, optional
|
||||
* @return {Promise} Promise with object describing path
|
||||
*/
|
||||
SFTPClient.prototype.stat = function stat (location, session) {
|
||||
// create the lsCmd callback for this.sftpCmd
|
||||
var statCmd = function (resolve, reject) {
|
||||
return function (err, sftp) {
|
||||
if (err) {
|
||||
return reject(err)
|
||||
}
|
||||
sftp.stat(location, function (err, stat) {
|
||||
if (err) {
|
||||
return reject(err)
|
||||
}
|
||||
var attrs = statToAttrs(stat)
|
||||
attrs.path = location
|
||||
if (stat.isDirectory()) {
|
||||
attrs.type = 'directory'
|
||||
} else if (stat.isFile()) {
|
||||
attrs.type = 'file'
|
||||
} else {
|
||||
attrs.type = 'other'
|
||||
}
|
||||
resolve(attrs)
|
||||
})
|
||||
}
|
||||
}
|
||||
// return the value of the command
|
||||
return this.sftpCmd(statCmd, session)
|
||||
}
|
||||
|
||||
/**
|
||||
* get remote file contents into a Buffer
|
||||
*
|
||||
* @param {string} path - on filesystem to stat
|
||||
* @param {ssh2.Client} [session] - existing ssh2 connection, optional
|
||||
* @return {Promise} Promise with Buffer on resolve
|
||||
*/
|
||||
SFTPClient.prototype.getBuffer = function getBuffer (location, session) {
|
||||
var getBufferCmd = function (resolve, reject) {
|
||||
return function (err, sftp) {
|
||||
if (err) {
|
||||
return reject(err)
|
||||
}
|
||||
sftp.open(location, 'r', function (err, handle) {
|
||||
if (err) {
|
||||
return reject(err)
|
||||
}
|
||||
sftp.fstat(handle, function (err, stat) {
|
||||
if (err) {
|
||||
return reject(err)
|
||||
}
|
||||
var bytes = stat.size
|
||||
var buffer = Buffer(bytes)
|
||||
if (bytes === 0) {
|
||||
return resolve(buffer)
|
||||
}
|
||||
buffer.fill(0)
|
||||
var cb = function (err, readBytes, offsetBuffer, position) {
|
||||
if (err) {
|
||||
return reject(err)
|
||||
}
|
||||
position = position + readBytes
|
||||
bytes = bytes - readBytes
|
||||
if (bytes < 1) {
|
||||
sftp.close(handle, function (err) {
|
||||
if (err) {
|
||||
reject(err)
|
||||
} else {
|
||||
resolve(buffer)
|
||||
}
|
||||
})
|
||||
} else {
|
||||
sftp.read(handle, buffer, position, bytes, position, cb)
|
||||
}
|
||||
}
|
||||
sftp.read(handle, buffer, 0, bytes, 0, cb)
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
return this.sftpCmd(getBufferCmd, session)
|
||||
}
|
||||
|
||||
/**
|
||||
* put buffer to remote file
|
||||
*
|
||||
* @param {Buffer} - Buffer containing file contents
|
||||
* @param {string} path - on filesystem to stat
|
||||
* @param {ssh2.Client} [session] - existing ssh2 connection, optional
|
||||
* @return {Promise} Promise with boolean true if tranfer was successful
|
||||
*/
|
||||
SFTPClient.prototype.putBuffer = function putBuffer (buffer, location, session) {
|
||||
var putBufferCmd = function (resolve, reject) {
|
||||
return function (err, sftp) {
|
||||
if (err) {
|
||||
return reject(err)
|
||||
}
|
||||
sftp.open(location, 'w', function (err, handle) {
|
||||
if (err) {
|
||||
return reject(err)
|
||||
}
|
||||
sftp.write(handle, buffer, 0, buffer.length, 0, function (err) {
|
||||
if (err) {
|
||||
return reject(err)
|
||||
} else {
|
||||
sftp.close(handle, function (err) {
|
||||
if (err) {
|
||||
reject(err)
|
||||
} else {
|
||||
resolve(true)
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
return this.sftpCmd(putBufferCmd, session)
|
||||
}
|
||||
|
||||
/**
|
||||
* get remote file and save it locally
|
||||
*
|
||||
* @param {string} remotepath - path to remote file
|
||||
* @param {string} localpath - destination path on local filesystem
|
||||
* @param {ssh2.Client} [session] - existing ssh2 connection, optional
|
||||
*/
|
||||
SFTPClient.prototype.get = function get (remote, local, session) {
|
||||
var getCmd = function (resolve, reject) {
|
||||
return function (err, sftp) {
|
||||
if (err) {
|
||||
return reject(err)
|
||||
}
|
||||
sftp.fastGet(remote, local, function (err) {
|
||||
if (err) {
|
||||
reject(err)
|
||||
} else {
|
||||
resolve(true)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
return this.sftpCmd(getCmd, session)
|
||||
}
|
||||
|
||||
/**
|
||||
* put local file in remote path
|
||||
*
|
||||
* @param {string} localpath - path to local file
|
||||
* @param {string} remotepath - destination path on remote filesystem
|
||||
* @param {ssh2.Client} [session] - existing ssh2 connection, optional
|
||||
*/
|
||||
SFTPClient.prototype.put = function put (local, remote, session) {
|
||||
var putCmd = function (resolve, reject) {
|
||||
return function (err, sftp) {
|
||||
if (err) {
|
||||
return reject(err)
|
||||
}
|
||||
sftp.fastPut(local, remote, function (err) {
|
||||
if (err) {
|
||||
reject(err)
|
||||
} else {
|
||||
resolve(true)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
return this.sftpCmd(putCmd, session)
|
||||
}
|
||||
|
||||
/**
|
||||
* remove remote file
|
||||
*
|
||||
* @param {string} path - remote file to remove
|
||||
* @param {ssh2.Client} [session] - existing ssh2 connection, optional
|
||||
*/
|
||||
SFTPClient.prototype.rm = function rm (location, session) {
|
||||
var rmCmd = function (resolve, reject) {
|
||||
return function (err, sftp) {
|
||||
if (err) {
|
||||
reject(err)
|
||||
return
|
||||
}
|
||||
sftp.unlink(location, function (err) {
|
||||
if (err) {
|
||||
reject(err)
|
||||
} else {
|
||||
resolve(true)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
return this.sftpCmd(rmCmd, session)
|
||||
}
|
||||
|
||||
/**
|
||||
* move remote file from one spot to another
|
||||
*
|
||||
* @param {string} source - remote filesystem source path
|
||||
* @param {string} destination - remote filesystem desitnation path
|
||||
* @param {ssh2.Client} [session] - existing ssh2 connection, optional
|
||||
*/
|
||||
SFTPClient.prototype.mv = function rm (src, dest, session) {
|
||||
var mvCmd = function (resolve, reject) {
|
||||
return function (err, sftp) {
|
||||
if (err) {
|
||||
return reject(err)
|
||||
}
|
||||
sftp.rename(src, dest, function (err) {
|
||||
if (err) {
|
||||
reject(err)
|
||||
} else {
|
||||
resolve(true)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
return this.sftpCmd(mvCmd, session)
|
||||
}
|
||||
|
||||
/**
|
||||
* removes and empty directory
|
||||
*
|
||||
* @param {string} path - remote directroy to remove
|
||||
* @param {ssh2.Client} [session] - existing ssh2 connection, optional
|
||||
*/
|
||||
SFTPClient.prototype.rmdir = function rmdir (path, session) {
|
||||
var rmdirCmd = function (resolve, reject) {
|
||||
return function (err, sftp) {
|
||||
if (err) {
|
||||
return reject(err)
|
||||
}
|
||||
sftp.rmdir(path, function (err) {
|
||||
if (err) {
|
||||
return reject(err)
|
||||
} else {
|
||||
return resolve(true)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
return this.sftpCmd(rmdirCmd, session)
|
||||
}
|
||||
|
||||
/**
|
||||
* makes a directory
|
||||
*
|
||||
* @param {string} path - remote directory to be created
|
||||
* @param {ssh2.Client} [session] - existing ssh2 connection, optional
|
||||
*/
|
||||
SFTPClient.prototype.mkdir = function mkdir (path, session) {
|
||||
var mkdirCmd = function (resolve, reject) {
|
||||
return function (err, sftp) {
|
||||
if (err) {
|
||||
return reject(err)
|
||||
}
|
||||
sftp.mkdir(path, function (err) {
|
||||
if (err) {
|
||||
return reject(err)
|
||||
} else {
|
||||
return resolve(true)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
return this.sftpCmd(mkdirCmd, session)
|
||||
}
|
||||
|
||||
/**
|
||||
* stream file contents from remote file
|
||||
*
|
||||
* @parm {string} path - remote file path
|
||||
* @parm {writableStream} writableStream - writable stream to pipe read data to
|
||||
* @parm {ssh2.Client} [session] - existing ssh2 connection
|
||||
*/
|
||||
SFTPClient.prototype.getStream = function getStream (path, writableStream, session) {
|
||||
var getStreamCmd = function (resolve, reject) {
|
||||
return function (err, sftp) {
|
||||
if (!writableStream.writable) {
|
||||
return reject(new Error('Stream must be a writable stream'))
|
||||
}
|
||||
if (err) {
|
||||
return reject(err)
|
||||
}
|
||||
sftp.stat(path, function (err, stat) {
|
||||
if (err) {
|
||||
return reject(err)
|
||||
}
|
||||
var bytes = stat.size
|
||||
if (bytes > 0) {
|
||||
bytes -= 1
|
||||
}
|
||||
try {
|
||||
var stream = sftp.createReadStream(path, {start: 0, end: bytes})
|
||||
} catch (err) {
|
||||
return reject(err)
|
||||
}
|
||||
stream.pipe(writableStream)
|
||||
stream.on('end', function () {
|
||||
resolve(true)
|
||||
})
|
||||
stream.on('error', function (err) {
|
||||
reject(err)
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
return this.sftpCmd(getStreamCmd, session)
|
||||
}
|
||||
|
||||
/**
|
||||
* stream file contents from local file
|
||||
*
|
||||
* @parm {string} path - remote file path
|
||||
* @parm {writableStream} writableStream - writable stream to pipe read data to
|
||||
* @parm {ssh2.Client} [session] - existing ssh2 connection
|
||||
*/
|
||||
SFTPClient.prototype.putStream = function putStream (path, readableStream, session) {
|
||||
var putStreamCmd = function (resolve, reject) {
|
||||
return function (err, sftp) {
|
||||
if (!readableStream.readable) {
|
||||
return reject(new Error('Stream must be a readable stream'))
|
||||
}
|
||||
if (err) {
|
||||
return reject(err)
|
||||
}
|
||||
try {
|
||||
var stream = sftp.createWriteStream(path)
|
||||
} catch (err) {
|
||||
return reject(err)
|
||||
}
|
||||
readableStream.pipe(stream)
|
||||
stream.on('finish', function () {
|
||||
return resolve(true)
|
||||
})
|
||||
stream.on('error', function (err) {
|
||||
return reject(err)
|
||||
})
|
||||
}
|
||||
}
|
||||
return this.sftpCmd(putStreamCmd, session)
|
||||
}
|
||||
|
||||
// export client
|
||||
module.exports = SFTPClient
|
||||
63
build/node_modules/sftp-promises/package.json
generated
vendored
Normal file
63
build/node_modules/sftp-promises/package.json
generated
vendored
Normal file
@@ -0,0 +1,63 @@
|
||||
{
|
||||
"_from": "sftp-promises",
|
||||
"_id": "sftp-promises@1.4.2",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha512-EMhHjVKASVRMIlLY/Qg5/JOyZgSlsiO4emdlhUsQAGMkHY/FZ/j9Ltn7kbBQkrKWJBTZ0wOvntpMjz4IGwxLqw==",
|
||||
"_location": "/sftp-promises",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "tag",
|
||||
"registry": true,
|
||||
"raw": "sftp-promises",
|
||||
"name": "sftp-promises",
|
||||
"escapedName": "sftp-promises",
|
||||
"rawSpec": "",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "latest"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"#USER",
|
||||
"/"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/sftp-promises/-/sftp-promises-1.4.2.tgz",
|
||||
"_shasum": "46b4285bc427e998dbfb185692620d7be65c54c1",
|
||||
"_spec": "sftp-promises",
|
||||
"_where": "/Users/asciidisco/Desktop/asciidisco.com/build",
|
||||
"author": {
|
||||
"name": "Dave Sanderson"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/brokenbot/sftp-promises/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"dependencies": {
|
||||
"ssh2": "^0.5.1",
|
||||
"ssh2-streams": "^0.1.8"
|
||||
},
|
||||
"deprecated": false,
|
||||
"description": "SFTP Promise wrapper for ssh2 SFTP commands",
|
||||
"devDependencies": {
|
||||
"chai": "^3.3.0",
|
||||
"chai-as-promised": "^6.0.0",
|
||||
"mocha": "^3.0.2",
|
||||
"standard": "^9.0.2"
|
||||
},
|
||||
"homepage": "https://github.com/brokenbot/sftp-promises#readme",
|
||||
"keywords": [
|
||||
"sftp",
|
||||
"promises",
|
||||
"ssh2"
|
||||
],
|
||||
"license": "BSD-3-Clause",
|
||||
"main": "index.js",
|
||||
"name": "sftp-promises",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/brokenbot/sftp-promises.git"
|
||||
},
|
||||
"scripts": {
|
||||
"cover": "istanbul cover _mocha -- -R spec",
|
||||
"test": "mocha"
|
||||
},
|
||||
"version": "1.4.2"
|
||||
}
|
||||
BIN
build/node_modules/sftp-promises/test/fixtures/test.dat
generated
vendored
Normal file
BIN
build/node_modules/sftp-promises/test/fixtures/test.dat
generated
vendored
Normal file
Binary file not shown.
0
build/node_modules/sftp-promises/test/fixtures/zero.test
generated
vendored
Normal file
0
build/node_modules/sftp-promises/test/fixtures/zero.test
generated
vendored
Normal file
0
build/node_modules/sftp-promises/test/mocha.opts
generated
vendored
Normal file
0
build/node_modules/sftp-promises/test/mocha.opts
generated
vendored
Normal file
229
build/node_modules/sftp-promises/test/test.js
generated
vendored
Normal file
229
build/node_modules/sftp-promises/test/test.js
generated
vendored
Normal file
@@ -0,0 +1,229 @@
|
||||
/* global describe, it */
|
||||
|
||||
var fs = require('fs')
|
||||
|
||||
var chai = require('chai')
|
||||
var chaiAsPromised = require('chai-as-promised')
|
||||
chai.use(chaiAsPromised)
|
||||
|
||||
var should = chai.should() // eslint-disable-line no-unused-vars
|
||||
|
||||
var config = {
|
||||
host: process.env.SFTPHOST || 'localhost',
|
||||
port: process.env.SFTPPORT || 22,
|
||||
username: process.env.SFTPUSER || 'vagrant',
|
||||
password: process.env.SFTPPASS || 'vagrant'
|
||||
}
|
||||
|
||||
var invalidLogin = {
|
||||
host: process.env.SFTPHOST || 'localhost',
|
||||
port: process.env.SFTPPORT || 22,
|
||||
username: 'invaliduser',
|
||||
password: 'invalid password'
|
||||
}
|
||||
|
||||
var SFTPClient = require('../index')
|
||||
|
||||
var sftp = new SFTPClient(config)
|
||||
|
||||
// read in test.dat to buffer
|
||||
var buffer = fs.readFileSync('test/fixtures/test.dat')
|
||||
var zbuffer = fs.readFileSync('test/fixtures/zero.test')
|
||||
|
||||
describe('SFTPClient()', function () {
|
||||
it('new SFTPClient(config) should return SFTPClient', function () {
|
||||
var Client = new SFTPClient(config)
|
||||
return Client instanceof SFTPClient
|
||||
})
|
||||
it('new SFTPClient(config).config should equal config', function () {
|
||||
var Client = new SFTPClient(config)
|
||||
Client.config.should.equal(config)
|
||||
})
|
||||
it('SFTPClient() should return SFTPClient instance', function () {
|
||||
var Client = SFTPClient()
|
||||
return Client instanceof SFTPClient
|
||||
})
|
||||
it('stat("./") with invalid login should fail', function () {
|
||||
var Client = SFTPClient(invalidLogin)
|
||||
return Client.stat('./').should.be.rejected
|
||||
})
|
||||
it('stat("./") with invalid config should fail', function () {
|
||||
var Client = SFTPClient()
|
||||
return Client.stat('./').should.be.rejected
|
||||
})
|
||||
})
|
||||
|
||||
describe('session(config)', function () {
|
||||
it('session(config) should return valid session', function () {
|
||||
return sftp.session(config).should.be.fulfilled
|
||||
})
|
||||
it('should fail with due to invalid login', function () {
|
||||
return sftp.session(invalidLogin).should.be.rejected
|
||||
})
|
||||
it('session() should be rejected', function () {
|
||||
return sftp.session().should.be.rejected
|
||||
})
|
||||
it('stat("./", session) should be fullfilled', function () {
|
||||
return sftp.session(config).then(function (session) {
|
||||
return sftp.stat('./', session)
|
||||
}).should.be.fulfilled
|
||||
})
|
||||
})
|
||||
|
||||
describe('putBuffer(buffer, remote)', function () {
|
||||
it('put(buffer, "/tmp/test.dat") should transfer buffer', function () {
|
||||
return sftp.putBuffer(buffer, '/tmp/test.dat').should.eventually.be.true
|
||||
})
|
||||
it('put(buffer, "/unwritable") should transfer reject', function () {
|
||||
return sftp.putBuffer(buffer, '/unwritable').should.be.rejected
|
||||
})
|
||||
it('put(buffer, "/tmp/zero.test") should put zero byte buffer', function () {
|
||||
return sftp.putBuffer(zbuffer, '/tmp/zero.test').should.eventually.be.true
|
||||
})
|
||||
})
|
||||
|
||||
describe('getBuffer(remote)', function () {
|
||||
it('getBuffer("/tmp/test.dat") should tranfer file to buffer', function () {
|
||||
return sftp.getBuffer('/tmp/test.dat').then(function (rbuffer) {
|
||||
return rbuffer.equals(buffer)
|
||||
}).should.eventually.be.true
|
||||
})
|
||||
it('getBuffer("/nonexistantfile") should reject', function () {
|
||||
return sftp.getBuffer('/nonexistantfile').should.be.rejected
|
||||
})
|
||||
it('getBuffer("zero.test") should tranfer zero byte file', function () {
|
||||
return sftp.getBuffer('/tmp/zero.test').then(function (rbuffer) {
|
||||
return rbuffer.length
|
||||
}).should.eventually.equal(0)
|
||||
})
|
||||
})
|
||||
|
||||
describe('put(local, remote)', function () {
|
||||
it('should transfer local file to remote', function () {
|
||||
return sftp.put('test/fixtures/test.dat', '/tmp/test.dat').should.eventually.be.true
|
||||
})
|
||||
it('put("test/fixtures/test.dat", "/unwritable") shoule reject', function () {
|
||||
return sftp.put('test/fixtures/test.dat', '/unwritable').should.be.rejected
|
||||
})
|
||||
it('put("/nonexistantfile", "/tmp/test.dat") should reject', function () {
|
||||
return sftp.put('/nonexistantfile', '/tmp/test.dat').should.be.rejected
|
||||
})
|
||||
})
|
||||
|
||||
describe('get(remote, local)', function () {
|
||||
it('should transfer remote file locally', function () {
|
||||
return sftp.get('/tmp/test.dat', '/tmp/transfertest.remove').should.eventually.be.true
|
||||
})
|
||||
it('get("/tmp/test.dat", "/unwritable") should reject', function () {
|
||||
return sftp.get('/tmp/test.dat', '/unwritable').should.be.rejected
|
||||
})
|
||||
it('put("/nonexistantfile", "/tmp/test.dat") should reject', function () {
|
||||
return sftp.get('/nonexistantfile', '/tmp/test.dat').should.be.rejected
|
||||
})
|
||||
})
|
||||
|
||||
describe('getStream(path, writableStream)', function () {
|
||||
it('getStream("/tmp/test.dat", writableStream) should be true', function () {
|
||||
var stream = fs.createWriteStream('/dev/null')
|
||||
return sftp.getStream('/tmp/test.dat', stream).should.eventually.be.true
|
||||
})
|
||||
it('getStream("/tmp/test.dat", nonWritableStream) should reject', function () {
|
||||
return sftp.getStream('/tmp/test.dat', 'notastream').should.be.rejected
|
||||
})
|
||||
it('getStream("/nonexistantfile", writableStream) should reject', function () {
|
||||
var stream = fs.createWriteStream('/dev/null')
|
||||
return sftp.getStream('/nonexistantfile', stream).should.be.rejected
|
||||
})
|
||||
})
|
||||
|
||||
describe('putStream(path, readableStream)', function () {
|
||||
it('putStream("/tmp/test-stream.dat", readStream) should be true', function () {
|
||||
var stream = fs.createReadStream('test/fixtures/test.dat')
|
||||
return sftp.putStream('/tmp/test.dat', stream).should.eventually.be.true
|
||||
})
|
||||
it('getStream("/tmp/test.dat", nonReadableStream) should reject', function () {
|
||||
return sftp.putStream('/tmp/test.dat', 'notastream').should.be.rejected
|
||||
})
|
||||
it('getStream("/nonewritable/location", writableStream) should reject', function () {
|
||||
var stream = fs.createReadStream('test/fixtures/test.dat')
|
||||
return sftp.getStream('/cantwritehere', stream).should.be.rejected
|
||||
})
|
||||
})
|
||||
|
||||
describe('mv(source, dest)', function () {
|
||||
it('mv("/tmp/test.dat", "/tmp/test.mv.dat") should move a remote file', function () {
|
||||
return sftp.mv('/tmp/test.dat', '/tmp/test.mv.dat').should.eventually.be.true
|
||||
})
|
||||
it('mv("/tmp/nonexistant.file","/tmp/test.dat") should fail', function () {
|
||||
return sftp.mv('/tmp/nonexistant.file', '/tmp/test.dat').should.be.rejected
|
||||
})
|
||||
it('mv("/tmp/test.mv.dat", "/nonwritable/location" should fail', function () {
|
||||
return sftp.mv('/tmp/test.mv.dat', '/cantwritehere').should.be.rejected
|
||||
})
|
||||
})
|
||||
|
||||
describe('ls(path)', function () {
|
||||
it('ls("/") should return a valid directroy object', function () {
|
||||
return sftp.ls('./').should.eventually.contain({type: 'directory'})
|
||||
})
|
||||
it('ls("/tmp/zero.test") should return a valid file object', function () {
|
||||
return sftp.ls('/tmp/zero.test').should.eventually.contain({type: 'file'})
|
||||
})
|
||||
it('ls("/dev/null") should be of type other', function () {
|
||||
return sftp.ls('/dev/null').should.eventually.contain({type: 'other'})
|
||||
})
|
||||
it('ls("./nonexistantfile") should reject', function () {
|
||||
return sftp.ls('somenonexistant.file').should.be.rejected
|
||||
})
|
||||
})
|
||||
|
||||
describe('stat(path)', function () {
|
||||
it('stat("/tmp") should be true', function () {
|
||||
return sftp.stat('/tmp').should.eventually.contain({type: 'directory'})
|
||||
})
|
||||
it('stat("/tmp/zero.test") should be file', function () {
|
||||
return sftp.stat('/tmp/zero.test').should.eventually.contain({type: 'file'})
|
||||
})
|
||||
it('stat("/dev/null") should be type other', function () {
|
||||
return sftp.stat('/dev/null').should.eventually.contain({type: 'other'})
|
||||
})
|
||||
it('stat("/root") should fail', function () {
|
||||
return sftp.stat('/root/.bashrc').should.be.rejected
|
||||
})
|
||||
it('stat("/nonexistantfile")', function () {
|
||||
return sftp.stat('/nonexistantfile').should.be.rejected
|
||||
})
|
||||
})
|
||||
|
||||
describe('rm(path)', function () {
|
||||
it('should remove a remote file', function () {
|
||||
return sftp.rm('/tmp/test.mv.dat').should.eventually.be.true
|
||||
})
|
||||
it('should remove a remote file', function () {
|
||||
return sftp.rm('/tmp/zero.test').should.eventually.be.true
|
||||
})
|
||||
it('rm("/tmp") should reject', function () {
|
||||
return sftp.rm('/tmp').should.eventually.rejected
|
||||
})
|
||||
})
|
||||
|
||||
describe('mkdir(path)', function () {
|
||||
it('mkdir("/tmp/testdir") should reslove', function () {
|
||||
return sftp.mkdir('/tmp/testdir').should.eventually.be.true
|
||||
})
|
||||
it('mkdir("/nonewritable") should reject', function () {
|
||||
return sftp.mkdir('/nowriteabledir').should.be.rejected
|
||||
})
|
||||
})
|
||||
|
||||
describe('rmdir(path)', function () {
|
||||
it('rmdir("/tmp/testdir") should be true', function () {
|
||||
return sftp.rmdir('/tmp/testdir').should.eventually.be.true
|
||||
})
|
||||
it('rmdir("/tmp") should reject', function () {
|
||||
return sftp.rmdir('/tmp').should.be.rejected
|
||||
})
|
||||
it('rmdir("/nonexistentdir") should be rejected', function () {
|
||||
return sftp.rmdir('/noexistantdir').should.be.rejected
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user