sergi/jsftp

Can't get debug info

Opened this issue · 3 comments

I run this example and can't get any debug info. Where is my mistake?

var Ftp = new JSFtp({
  host: "myserver.com",
  port: 3331,
  user: "user",
  pass: "1234",
  debugMode: true
});

Ftp.on('jsftp_debug', function(eventType, data) {
  console.log('DEBUG: ', eventType);
  console.log(JSON.stringify(data, null, 2));
});

Ftp.ls(".", function(err, res) {
  res.forEach(function(file) {
    console.log(file.name);
  });
});

If you are looking to hook into an event, for the purposes of logging etc, then you can listen for the data event which logs all FTP server responses. Looks like the docs haven't been updated. If you try this instead....

Ftp.on('data', function(data){
    console.log(data);
})

This gives you all the commands and FTP codes that are received from the server, which helps me as I just want to log out a few of the commands to my own app log.

Also, you can listen for connect, error, progress and timeout events.

If it's the internal workings of the module, so seeing everything going on, add a DEBUG=jsftp:* as an environment variable, and this will enable all debug commands and you'll get an output such as....

(node:20588) DeprecationWarning: Ftp.raw[pass](args): Use Ftp.raw('pass args') instead.
  jsftp:response { code: 230,
  jsftp:response   text: '230 User dan logged in.',
  jsftp:response   isMark: false,
  jsftp:response   isError: false } +117ms
  jsftp:response 230 User dan logged in. +0ms
  jsftp:command type I +0ms
  jsftp:command type I +1ms
(node:20588) DeprecationWarning: Ftp.raw[type](args): Use Ftp.raw('type args') instead.
  jsftp:response { code: 200,
  jsftp:response   text: '200 Type set to I.',
  jsftp:response   isMark: false,
  jsftp:response   isError: false } +0ms
  jsftp:response 200 Type set to I. +0ms
  jsftp:command pasv +0ms
  jsftp:command pasv +0ms
  jsftp:response { code: 227,
  jsftp:response   text: '227 Entering Passive Mode (127,0,0,1,200,219)',
  jsftp:response   isMark: false,
  jsftp:response   isError: false } +0ms
  jsftp:response 227 Entering Passive Mode (127,0,0,1,200,219) +0ms
  jsftp:command retr /Users/dan/Desktop/isilon1/test2.dat +2ms
  jsftp:command retr /Users/dan/Desktop/isilon1/test2.dat +0ms
  jsftp:response { code: 150,
  jsftp:response   text: '150 Opening BINARY mode data connection for \'/Users/dan/Desktop/isilon1/test2.dat\' (104857600 bytes).',
  jsftp:response   isMark: true,
  jsftp:response   isError: false } +0ms
  jsftp:response 150 Opening BINARY mode data connection for '/Users/dan/Desktop/isilon1/test2.dat' (104857600 bytes). +1ms
  jsftp:response { code: 226,
  jsftp:response   text: '226 Transfer complete.',
  jsftp:response   isMark: false,
  jsftp:response   isError: false } +495ms
  jsftp:response 226 Transfer complete. +1ms

You can also set the DEBUG environment variable to jsftp:general,jsftp:response,jsftp:command (leave out what you don't need) and run your program.

This command does both: DEBUG=jsftp:general,jsftp:response,jsftp:command node ./path/to/program

More info on https://www.npmjs.com/package/debug, which jsftp uses. And indeed, the docs should be updated.