mscdex / node-ftp

An FTP client module for node.js
MIT License
1.13k stars 243 forks source link

Can't get files after reading directory #144

Closed jsatk closed 6 years ago

jsatk commented 8 years ago
var Client = require('ftp');
var fs = require('fs');

var c = new Client();

c.on('ready', function() {
  c.list(function(err, list) {
    if (err) throw err;
    console.dir(list);
    c.get('textfile.txt', function(err, stream) {
      if (err) throw err;
      console.log('stream: ', stream);
      stream.once('close', function() { console.log('closed'); c.end(); });
      stream.pipe(fs.createWriteStream('foo.local-copy.txt'));
    });
  });
});

c.connect(cred);

Sample code above. get does not return a stream. What am I doing wrong?

jairamaswamy commented 8 years ago

Please try like this. I beleive no need to use c.list instead you can use like c.get('folderName/test.xml', function (err, stream)

c.on('ready', function () { c.get('folderName/test.xml', function (err, stream) { if (err) { console.log("Error in FTP to get/Read the file: " + +err.message); return; }; stream.once('close', function () { c.end(); }); stream.pipe(fs.createWriteStream('test.xml')); }); }); callback(null); }, 0);

Also I want to know where you are deploying this code?

jsatk commented 6 years ago

Closing as this is simply outdated and no longer a concern.