Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const Transform = require('stream').Transform;
- const util = require('util');
- const transformComponent = module.exports = function(options) {
- if (!(this instanceof transformComponent))
- return new Parser(options);
- Transform.call(this, options);
- };
- util.inherits(transformComponent, Transform);
- transformComponent.prototype._transform = function(data, encoding, callback) {
- this.push(data);
- callback();
- };
- transformComponent.prototype._flush = function(callback) {
- callback();
- };
- const Client = require('ftp');
- var ftp = new Client();
- var ftpComponent = function(host){
- this.host = host;
- this.port = 21;
- this.user = "";
- this.password = "";
- };
- function connectionProperties(){
- let properties ={
- host: this.host,
- port: this.port
- };
- if(this.user && this.user!== "")
- properties.user = this.user;
- if(this.password && this.password !== "")
- properties.password = this.password;
- return properties;
- }
- function download(filepath, target){
- ftp.on('ready', function () {
- ftp.get(filepath, function(err, stream) {
- if (err) throw err;
- stream.once('close', function() { ftp.end(); });
- stream.pipe(target);
- });
- });
- ftp.connect(this.connectionProperties());
- }
- function upload(source, filename){
- ftp.on('ready', function () {
- // Upload files to the server:
- ftp.put(source, filename, function(err) {
- if (err) throw err;
- ftp.end();
- });
- });
- ftp.connect(this.connectionProperties());
- }
- ftpComponent.prototype = {
- connectionProperties: connectionProperties,
- pull : download,
- push : upload
- }
- module.exports = ftpComponent;
- const ftp = require('./node_component/ftpComponent.js');
- const transform = require('./node_component/transformComponent.js');
- var ftpSourceObject = new ftp('host A');
- var ftpTargetObject = new ftp('host B');
- ftpSourceObject.user = usernameA;
- ftpSourceObject.password = passwordA;
- ftpTargetObject.user = usernameB;
- ftpTargetObject.password = passwordB;
- var temp = new transform();
- ftpSourceObject.pull('file.txt', temp);
- ftpTargetObject.push(temp, 'file-cp.txt');
Add Comment
Please, Sign In to add comment