le-ftp
v1.0.5
Published
Watch local directory and upload changes to ftp
Downloads
2
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.js
installed - In the directory where
le-ftp
is 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-ftp
resides, 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-ftp
object. So, in the above example it would bex.stop()
- If you want to modify the
testftp.js
so 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.css
andcss
will both work.
Important if you receive ECONNREFUSED error
- On some networks the
node.js ftp
module cannot connect and returns ECONNREFUSED error - This is not an issue with
le-ftp
itself, butnode.js ftp
module, on whichle-ftp
depends - This issue could be resolved by setting
keep alive
option tofalse
insidenode.js ftp
module- editing file
node_modules/ftp/lib/connections.js
- Open the file and go to line 106, which says
socket.setKeepAlive(true);
- Change
true
tofalse
, so that it now says socket.setKeepAlive(false);
- editing file