Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ftps

Package Overview
Dependencies
Maintainers
1
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ftps - npm Package Compare versions

Comparing version 0.4.3 to 0.4.4

test/test.js

156

index.js
var spawn = require('child_process').spawn,
_ = require('underscore')
_ = require('lodash');

@@ -18,3 +18,3 @@ /*

** retryMultiplier: 1, // Optional, Multiplier by which retryInterval is multiplied each time new attempt fails. Defaults to 1
** requiresPassword: true, // Optional, defaults to true
** requiresPassword: true, // Optional, defaults to true
** autoConfirm: true, // Optional, defaults to false

@@ -30,5 +30,5 @@ ** cwd: '', // Optional, defaults to the directory from where the script is executed

var FTP = function (options) {
this.initialize(options)
this.cmds = []
}
this.initialize(options);
this.cmds = [];
};

@@ -49,21 +49,21 @@ FTP.prototype.initialize = function (options) {

additionalLftpCommands: "" // Additional commands to pass to lftp, splitted by ';'
}
};
// Extend options with defaults
var opts = _.pick(_.extend(defaults, options), 'host', 'username', 'password', 'port', 'escape', 'retries', 'timeout', 'retryInterval', 'retryIntervalMultiplier', 'requiresPassword', 'protocol', 'autoConfirm', 'cwd', 'additionalLftpCommands')
var opts = _.pick(_.extend(defaults, options), 'host', 'username', 'password', 'port', 'escape', 'retries', 'timeout', 'retryInterval', 'retryIntervalMultiplier', 'requiresPassword', 'protocol', 'autoConfirm', 'cwd', 'additionalLftpCommands');
// Validation
if (!opts.host) throw new Error('You need to set a host.')
if (!opts.username) throw new Error('You need to set an username.')
if (opts.requiresPassword === true && !opts.password) throw new Error('You need to set a password.')
if (options.protocol && typeof options.protocol !== 'string') throw new Error('Protocol needs to be of type string.')
if (!opts.host) throw new Error('You need to set a host.');
if (!opts.username) throw new Error('You need to set an username.');
if (opts.requiresPassword === true && !opts.password) throw new Error('You need to set a password.');
if (options.protocol && typeof options.protocol !== 'string') throw new Error('Protocol needs to be of type string.');
// Setting options
if (options.protocol && opts.host.indexOf(options.protocol + '://') !== 0)
opts.host = options.protocol + '://' + options.host
opts.host = options.protocol + '://' + options.host;
if (opts.port)
opts.host = opts.host + ':' + opts.port
opts.host = opts.host + ':' + opts.port;
this.options = opts
}
this.options = opts;
};

@@ -76,32 +76,32 @@ FTP.prototype.escapeshell = function(cmd) {

if (this.options.escape) {
return this.escapeshell(cmd)
return this.escapeshell(cmd);
}
return cmd
}
return cmd;
};
FTP.prototype.exec = function (cmds, callback) {
if (typeof cmds === 'string')
cmds = cmds.split(';')
cmds = cmds.split(';');
if (Array.isArray(cmds))
this.cmds = this.cmds.concat(cmds)
this.cmds = this.cmds.concat(cmds);
if (typeof cmds === 'function' && !callback)
callback = cmds
callback = cmds;
if (!callback)
throw new Error('Callback is missing to exec() function.')
var cmd = ''
throw new Error('Callback is missing to exec() function.');
var cmd = '';
// Only support SFTP or FISH for ssl autoConfirm
if((this.options.protocol.toLowerCase() === "sftp" || this.options.protocol.toLowerCase() === "fish") && this.options.autoConfirm)
cmd += 'set ' + this.options.protocol.toLowerCase() + ':auto-confirm yes;'
cmd += 'set net:max-retries ' + this.options.retries + ';'
cmd += 'set net:timeout ' + this.options.timeout + ';'
cmd += 'set net:reconnect-interval-base ' + this.options.retryInterval + ';'
cmd += 'set net:reconnect-interval-multiplier ' + this.options.retryIntervalMultiplier + ';'
cmd += this.options.additionalLftpCommands + ";"
cmd += 'open -u "'+ this._escapeshell(this.options.username) + '","' + this._escapeshell(this.options.password) + '" "' + this.options.host + '";'
cmd += this.cmds.join(';')
this.cmds = []
cmd += 'set ' + this.options.protocol.toLowerCase() + ':auto-confirm yes;';
cmd += 'set net:max-retries ' + this.options.retries + ';';
cmd += 'set net:timeout ' + this.options.timeout + ';';
cmd += 'set net:reconnect-interval-base ' + this.options.retryInterval + ';';
cmd += 'set net:reconnect-interval-multiplier ' + this.options.retryIntervalMultiplier + ';';
cmd += this.options.additionalLftpCommands + ";";
cmd += 'open -u "'+ this._escapeshell(this.options.username) + '","' + this._escapeshell(this.options.password) + '" "' + this.options.host + '";';
cmd += this.cmds.join(';');
this.cmds = [];
var spawnoptions;

@@ -112,59 +112,59 @@ if(this.options.cwd){

var lftp = spawn('lftp', ['-c', cmd], spawnoptions)
var data = ""
var error = ""
var lftp = spawn('lftp', ['-c', cmd], spawnoptions);
var data = "";
var error = "";
lftp.stdout.on('data', function (res) {
data += res
})
data += res;
});
lftp.stderr.on('data', function (res) {
error += res
})
error += res;
});
lftp.on('error', function ( err ) {
if (callback)
callback(err, { error: error || null, data: data })
callback = null // Make sure callback is only called once, whether 'exit' event is triggered or not.
})
callback(err, { error: error || null, data: data });
callback = null; // Make sure callback is only called once, whether 'exit' event is triggered or not.
});
lftp.on('exit', function (code) {
if (callback)
callback(null, { error: error || null, data: data })
})
return lftp
}
callback(null, { error: error || null, data: data });
});
return lftp;
};
FTP.prototype.raw = function (cmd) {
if (cmd && typeof cmd === 'string')
this.cmds.push(cmd)
return this
}
this.cmds.push(cmd);
return this;
};
FTP.prototype.ls = function () { return this.raw('ls') }
FTP.prototype.pwd = function () { return this.raw('pwd') }
FTP.prototype.cd = function (directory) { return this.raw('cd ' + this._escapeshell(directory)) }
FTP.prototype.cat = function (path) { return this.raw('cat ' + this._escapeshell(path)) }
FTP.prototype.ls = function () { return this.raw('ls'); };
FTP.prototype.pwd = function () { return this.raw('pwd'); };
FTP.prototype.cd = function (directory) { return this.raw('cd ' + this._escapeshell(directory)); };
FTP.prototype.cat = function (path) { return this.raw('cat ' + this._escapeshell(path)); };
FTP.prototype.put = function (localPath, remotePath) {
if (!localPath)
return this
return this;
if (!remotePath)
return this.raw('put '+this._escapeshell(localPath))
return this.raw('put '+this._escapeshell(localPath)+' -o '+this._escapeshell(remotePath))
}
FTP.prototype.addFile = FTP.prototype.put
return this.raw('put '+this._escapeshell(localPath));
return this.raw('put '+this._escapeshell(localPath)+' -o '+this._escapeshell(remotePath));
};
FTP.prototype.addFile = FTP.prototype.put;
FTP.prototype.get = function (remotePath, localPath) {
if (!remotePath)
return this
return this;
if (!localPath)
return this.raw('get '+this._escapeshell(remotePath))
return this.raw('get '+this._escapeshell(remotePath)+' -o '+this._escapeshell(localPath))
}
FTP.prototype.getFile = FTP.prototype.get
return this.raw('get '+this._escapeshell(remotePath));
return this.raw('get '+this._escapeshell(remotePath)+' -o '+this._escapeshell(localPath));
};
FTP.prototype.getFile = FTP.prototype.get;
FTP.prototype.mv = function (from, to) {
if (!from || !to)
return this
return this.raw('mv ' + this._escapeshell(from) + ' ' + this._escapeshell(to))
}
FTP.prototype.move = FTP.prototype.mv
FTP.prototype.rm = function () { return this.raw('rm ' + Array.prototype.slice.call(arguments).map(this._escapeshell).join(' ')) }
FTP.prototype.remove = FTP.prototype.rm
FTP.prototype.rmdir = function () { return this.raw('rmdir ' + Array.prototype.slice.call(arguments).map(this._escapeshell).join(' ')) }
return this;
return this.raw('mv ' + this._escapeshell(from) + ' ' + this._escapeshell(to));
};
FTP.prototype.move = FTP.prototype.mv;
FTP.prototype.rm = function () { return this.raw('rm ' + Array.prototype.slice.call(arguments).map(this._escapeshell.bind(this)).join(' ')); };
FTP.prototype.remove = FTP.prototype.rm;
FTP.prototype.rmdir = function () { return this.raw('rmdir ' + Array.prototype.slice.call(arguments).map(this._escapeshell.bind(this)).join(' ')); };
module.exports = FTP
module.exports = FTP;
{
"name": "ftps",
"version": "0.4.3",
"version": "0.4.4",
"author": {

@@ -24,3 +24,3 @@ "name" : "Sébastien Chopin" ,

"dependencies": {
"underscore": ">=1.4.4"
"lodash": "^4.4.0"
},

@@ -27,0 +27,0 @@ "devDependencies": {},

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc