le-ftp
v1.0.5
Published
Watch local directory and upload changes to ftp
Maintainers
Readme
le-ftp
Watch local directory (and its sub-directories) for changes and uploads changed files via ftp - node.js
This is not fully tested and should not be used in any critical applications.
Usage
- Make sure you have
node.jsinstalled - In the directory where
le-ftpis installed, create filetestftp.js - Copy and paste into the new file the following:
LEftp = require('le-ftp');
var x = new LEftp({
"host" : "", // ftp host address, eg. my.server.com
"port" : 21,
"user" : '', // Your ftp username
"password" : '', // Your ftp password
"watchList": [
{
"localRootDir" : "C:/local/folder1",
"remoteRootDir" : 'public_html/remote/dir1'
},
{
"localRootDir" : "C:/my/local/folder2",
"remoteRootDir" : 'public_html/remote/dir2'
}
],
// The following two parameters are depricated. Use watchList array instead
// "localRootDir" : "C:/my/local/folder", // Depricated, use watchList array instead
// "remoteRootDir": 'public_html/remote/dir', // Depricated, use watchList array instead
"frequency" : 1, // Number of seconds between each scan
"ext" : ['.css','.js','.html','txt','jpg'],
"onStartUploadAll" : true // On start, upload all files (that match the "watch criteria").
});- Edit the settings you just pasted (see Configuration Parameters below)
- From command line in the directory where
le-ftpresides, runnode le-ftp - Current files (that match your criteria) will be uploaded and program will keep running
- To stop watching
- from command line, use
[Ctrl]+[c] - from script, call
.stop()method on thele-ftpobject. So, in the above example it would bex.stop() - If you want to modify the
testftp.jsso that watching is stopped after, say, 100seconds, add the following code totestftp.js:
// Schedule to stop watching in 100 seconds (100,000 milliseconds)
setTimeout(
function() {x.stop();} ,
100 * 1000 // Schedule stop after 100 seconds (100,000 milliseconds)
);Configuration Parameters
host: 'myftpserver.domain.com'- address of the ftp serverport: 21- ftp server portremoteRootDir: ''- Remote root directory: Local files will be copied to this directorylocalRootDir: ''- Local root directory: Local directory to watchuser: ''- Ftp usernamepassword: ''- Ftp passwordwatchList: [- Array of folders to watch and corresponding upload target directories{- Beging first object describing the pair of folder to watch and its upload target directorylocalRootDir: 'C:/my/local/folder1',- first local folder to watchremoteRootDir: 'public_html/remote/dir1'- first remote upload target directory},- End first object{- Beging second object describing the pair of folder to watch and its upload target directorylocalRootDir: 'C:/my/local/folder2',- second local folder to watchremoteRootDir: 'public_html/remote/dir2'- second remote upload target directory},- End Second object
],- End of array of folders to watchlocalRootDir : "C:/dir"- Depricated. Full path to local folder to be copied to the FTP server. Use Unix backslash "/"remoteRootDir : 'public_html/dev.clubfinance.uk/angular',- Depricated Remote folder, starting from your FTP rootfrequency: 1- number of seconds between each scan. Decimals (e.g.0.1) are acceptableext: ['css','js','html','txt']- if you want to only include files with certain extensions, list the extensions here as an array of strings:['css','js','html']. No need to prefix extensions with '.', so.cssandcsswill both work.
Important if you receive ECONNREFUSED error
- On some networks the
node.js ftpmodule cannot connect and returns ECONNREFUSED error - This is not an issue with
le-ftpitself, butnode.js ftpmodule, on whichle-ftpdepends - This issue could be resolved by setting
keep aliveoption tofalseinsidenode.js ftpmodule- editing file
node_modules/ftp/lib/connections.js - Open the file and go to line 106, which says
socket.setKeepAlive(true);- Change
truetofalse, so that it now says socket.setKeepAlive(false);
- editing file
