Skip to content

Instantly share code, notes, and snippets.

@wayneashleyberry
Last active December 16, 2015 19:19
Show Gist options
  • Save wayneashleyberry/5484554 to your computer and use it in GitHub Desktop.
Save wayneashleyberry/5484554 to your computer and use it in GitHub Desktop.
FTP Uploader
var fs = require('fs');
var path = require('path');
var Ftp = require("jsftp");
var ftp = new Ftp({
host : "**********",
user : "**********",
pass : "*********"
});
var dir = 'files';
var upload = function (filename) {
var stream = fs.createReadStream(filename);
stream.pause();
ftp.getPutSocket("/test/"+path.basename(filename), function(err, socket) {
if (err) return console.error(err);
stream.pipe(socket);
stream.resume();
});
};
fs.watch(dir, {}, function (event, filename) {
if (filename === '.DS_Store') return;
fs.stat(path.join(dir, filename), function (err, stats) {
if (stats.isFile()) {
upload(path.join(dir, filename));
}
});
});
@assertchris
Copy link

What a champ!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment