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

ftp-deploy

Package Overview
Dependencies
Maintainers
1
Versions
48
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ftp-deploy - npm Package Compare versions

Comparing version 0.7.0 to 1.0.0

test/test-root/folder a/folder b/empty c/folder d/test-inside-d-1.txt

167

ftp-deploy.js

@@ -22,12 +22,11 @@ var fs = require('fs');

this.toTransfer;
this.transferred = 0;
this.total = 0;
var toTransfer; // eventually holds the result of dirParseSync()
var transferredFileCount = 0;
var ftp;
var localRoot;
var remoteRoot;
var parallelUploads = 1;
var partialDirectories = []; // holds list of directories to check & create (excluding local root path)
var partialFilePaths = []; // holds list of partial file paths to upload
//var parallelUploads = 1; // NOTE: this can be added in when sftp is supported
var exclude = [];
var currPath;
var authVals;
var continueOnError = false;

@@ -43,3 +42,2 @@

}
return true;

@@ -78,2 +76,3 @@ }

result[tmpPath] = [];
partialDirectories.push(tmpPath);
}

@@ -89,7 +88,6 @@ dirParseSync(currFile, result);

// check exclude rules
if (canIncludeFile(path.join(tmpPath, files[i]))) {
var partialFilePath = path.join(tmpPath, files[i]);
if (canIncludeFile(partialFilePath)) {
result[tmpPath].push(files[i]);
// increase total file count
thisDeployer.total++;
partialFilePaths.push(partialFilePath);
}

@@ -102,47 +100,19 @@ }

// A method for changing the remote working directory and creating one if it doesn't already exist
function ftpCwd(inPath, cb) {
// add leading slash if it is missing
if (inPath.charAt(0) !== '/') {
inPath = '/' + inPath;
}
//console.log("inPath pre-replace: " + inPath);
// remove double // if present
inPath = inPath.replace(/\/\//g, "/");
var wrdir = path.basename(inPath);
//console.log("inPath: " + inPath);
//console.log("inPath normalized: " + path.normalize(inPath));
//console.log("wrdir: " + wrdir);
ftp.raw.cwd(inPath, function(err) {
if (err) {
ftp.raw.mkd(inPath, function(err) {
if(err) {
//console.log(err);
cb(err);
} else {
ftpCwd(inPath, cb);
}
});
} else {
cb();
}
});
}
// A method for uploading a single file
function ftpPut(inFilename, cb) {
function ftpPut(partialFilePath, cb) {
var remoteFilePath = remoteRoot + "/" + partialFilePath;
remoteFilePath = remoteFilePath.replace(/\\/g, '/');
var fullLocalPath = path.join(localRoot, partialFilePath);
var emitData = {
totalFileCount: thisDeployer.total,
transferredFileCount: thisDeployer.transferred,
percentComplete: Math.round((thisDeployer.transferred / thisDeployer.total) * 100),
filename: inFilename,
relativePath: currPath
totalFileCount: partialFilePaths.length,
transferredFileCount: transferredFileCount,
percentComplete: Math.round((transferredFileCount / partialFilePaths.length) * 100),
filename: partialFilePath
};
thisDeployer.emit('uploading', emitData);
var fullPathName = path.join(localRoot, currPath, inFilename);
ftp.put(fullPathName, inFilename.replace(/\\/g, '/'), function (err) {
ftp.put(fullLocalPath, remoteFilePath, function (err) {
if (err) {

@@ -158,4 +128,4 @@ emitData.err = err;

} else {
thisDeployer.transferred++;
emitData.transferredFileCount = thisDeployer.transferred;
transferredFileCount++;
emitData.transferredFileCount = transferredFileCount;
thisDeployer.emit('uploaded', emitData);

@@ -165,33 +135,44 @@ cb();

});
}
function ftpMakeDirectoriesIfNeeded (cb) {
async.eachSeries(partialDirectories, ftpMakeRemoteDirectoryIfNeeded, function (err) {
cb(err);
});
}
// A method that processes a location - changes to a folder and uploads all respective files
function ftpProcessLocation (inPath, cb) {
if (!thisDeployer.toTransfer[inPath]) {
cb(new Error('Data for ' + inPath + ' not found'));
} else {
ftpCwd(remoteRoot + '/' + inPath.replace(/\\/gi, '/'), function (err) {
if (err) {
//console.error(err);
cb(err);
} else {
var files;
currPath = inPath;
files = thisDeployer.toTransfer[inPath];
async.mapLimit(files, parallelUploads, ftpPut, function (err) {
cb(err);
});
}
});
}
}
// A method for changing the remote working directory and creating one if it doesn't already exist
function ftpMakeRemoteDirectoryIfNeeded(partialRemoteDirectory, cb) {
// add the remote root, and clean up the slashes
var fullRemoteDirectory = remoteRoot + '/' + partialRemoteDirectory.replace(/\\/gi, '/');
// add leading slash if it is missing
if (fullRemoteDirectory.charAt(0) !== '/') {
fullRemoteDirectory = '/' + fullRemoteDirectory;
}
// remove double // if present
fullRemoteDirectory = fullRemoteDirectory.replace(/\/\//g, "/");
ftp.raw.cwd(fullRemoteDirectory, function(err) {
if (err) {
ftp.raw.mkd(fullRemoteDirectory, function(err) {
if(err) {
cb(err);
} else {
ftpMakeRemoteDirectoryIfNeeded(partialRemoteDirectory, cb);
}
});
} else {
cb();
}
});
}
this.deploy = function (config, cb) {
// Prompt for password if none was given
if (!config.password) {
read({prompt: 'Password for ' + config.username + '@' + config.host + ' (ENTER for none): ', default: '', silent:true}, function (err, res) {
config.password = res;
configComplete(config, cb);
config.password = res;
configComplete(config, cb);
});

@@ -217,4 +198,4 @@ } else {

ftp.useList = true;
thisDeployer.toTransfer = dirParseSync(localRoot);
toTransfer = dirParseSync(localRoot);
// Authentication and main processing of files

@@ -225,10 +206,15 @@ ftp.auth(config.username, config.password, function (err) {

} else {
// Iterating through all location from the `localRoot` in parallel
var locations = Object.keys(thisDeployer.toTransfer);
async.mapSeries(locations, ftpProcessLocation, function (err) {
ftpMakeDirectoriesIfNeeded(function (err) {
if (err) {
// if there was an error creating a remote directory we can't continue to upload files
cb(err);
} else {
ftp.raw.quit(function (err) {
cb(err);
async.eachSeries(partialFilePaths, ftpPut, function (err) {
if (err) {
cb(err);
} else {
ftp.raw.quit(function (err) {
cb(err);
});
}
});

@@ -239,3 +225,3 @@ }

});
};
}
};

@@ -245,9 +231,2 @@

// commonJS module systems
if (typeof module !== 'undefined' && "exports" in module) {
module.exports = FtpDeployer;
}
module.exports = FtpDeployer;
{
"name": "ftp-deploy",
"version": "0.7.0",
"version": "1.0.0",
"author": "Rick Bergfalk <rick.bergfalk@gmail.com> (http://rickbergfalk.com/)",
"description": "Ftp a folder from your local disk to an ftp destination. Does not delete from destination directory. Derived from grunt-ftp-deploy",
"keywords": [
"ftp",
"deploy"
"ftp",
"deploy"
],
"dependencies": {
"jsftp": "1.2.x",
"async": "0.2.x",
"jsftp": "1.3.x",
"async": "0.9.x",
"minimatch": "0.2.12",
"read": "1.0.5"
},
"repository" : {
"type": "git",
"repository": {
"type": "git",
"url": "git://github.com/rickbergfalk/ftp-deploy"
},
"bugs" : {
"bugs": {
"url": "https://github.com/rickbergfalk/ftp-deploy/issues"
},
"contributors": [
"contributors": [
{

@@ -31,5 +31,8 @@ "name": "Ondrej",

"url": "https://github.com/keyle"
}
}
],
"scripts": {
"test": "node test/test.js"
},
"main": "ftp-deploy"
}
# ftp-deploy
Ftp a folder from your local disk to a remote ftp destination. Does not delete from destination directory. Derived from [https://github.com/zonak/grunt-ftp-deploy](https://github.com/zonak/grunt-ftp-deploy "zonak/grunt-ftp-deploy").
Ftp a folder from your local disk to a remote ftp destination. Does not delete from destination directory.

@@ -39,4 +39,3 @@ A Node.js package.

data.percentComplete; // percent as a number 1 - 100
data.filename; // filename being uploaded
data.relativePath; // relative path to file being uploaded from local root location
data.filename; // partial path with filename being uploaded
});

@@ -66,2 +65,7 @@ ftpDeploy.on('uploaded', function(data) {

- 1.0.0
- refactored for (hopefully) easier to understand code
- brought jsftp to 1.3.x, async to 0.9.x
- removed relative path from uploading/uploaded event data. (filename contains file name and partial path)
- 0.7.x

@@ -68,0 +72,0 @@ - added prompting user for FTP password if none given in config

Sorry, the diff of this file is not supported yet

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