Last active
December 16, 2015 19:19
-
-
Save wayneashleyberry/5484554 to your computer and use it in GitHub Desktop.
FTP Uploader
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What a champ!