Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var EasyFtp = require('easy-ftp');
- var ftp = new EasyFTP();
- var config = {
- host: '',
- port: 21,
- username: '',
- password: ''
- };
- ftp.connect(config);
- var filesFrom=['/file1.txt','/anotherFile.txt','/moreFiles.txt','/a.txt','/x.txt']
- var filesTo=['/archived/file1.txt','/archived/anotherFile.txt','/archived/moreFiles.txt','/archived/a.txt','/archived/x.txt']
- for (var i = 0; i < filesFrom.length; i++) {
- ftp.mv(filesFrom[i], filesTo[i], function(err, newPath){
- if (err) { console.log(err) }
- });
- };
- ftp.close();
- function mvFiles(ftpObj, fromArray, toArray, callback) {
- let index = 0;
- let results = [];
- function next() {
- if (index < fromArray.length) {
- let i = index++;
- ftpObj.mv(fromArray[i], toArray[i], function(err, newPath) {
- if (err) {
- callback(err);
- } else {
- results[i] = newPath;
- next();
- }
- });
- } else {
- callback(null, results);
- }
- }
- next();
- }
- ftp.connect(config);
- var filesFrom =['/file1.txt','/anotherFile.txt','/moreFiles.txt','/a.txt','/x.txt'];
- var filesTo =['/archived/file1.txt','/archived/anotherFile.txt','/archived/moreFiles.txt','/archived/a.txt','/archived/x.txt'];
- mvFiles(ftp, filesFrom, filesTo, function(err, newPaths) {
- ftp.close();
- if (err) {
- // process error here
- } else {
- // all done here
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement