0

I'm using the ftps module and I've got lftp installed on Cygwin. I'm having trouble because my node js app looks like it's connecting fine but none of my commands are running. The documentation for the module isn't very detailed so I've just been trying what ever I can to get this running. I'm tying to get a file from the ftp site.

Here is my code:

var ftps = require('ftps');

// ftps connection
var ftp = new ftps ({
    host: 'test.ftpsite.com',
    username: 'test',
    password: 'test',
    protocol: 'sftp'
});

// look at remote directory
console.log(ftp);
ftp.cd('TestDir/').get('/UploadTest.txt', '/cygdrive/c/Users/Administrator/UploadTest.txt').exec(console.log);

Output:

CMO-Application-Server>node app.js
{ options:
   { host: 'test.ftpsite.com',
     username: 'test',
     password: 'test' },
  cmds: [] }

At this point in the output, the app just hangs up like it's attempting to run the commands. I've been letting it run for about 10 minutes now and still nothing.

Steffen Ullrich
  • 114,247
  • 10
  • 131
  • 172
user
  • 715
  • 4
  • 13
  • 32
  • If you want to get a file from an ftp site you need to use 'ftp' or 'ftps' (FTP with SSL) as protocol, not 'sftp' (file transfer over SSH). Also, this module is just a wrapper around lftp command line, so try first just using the command line. – Steffen Ullrich Apr 28 '14 at 16:01
  • I was able to do it with the command line. I've also tried using ftp and ftps in the module and got the same result. My boss wants me to do it in python now so I'm moving to that instead... – user Apr 28 '14 at 17:49

1 Answers1

1

For sftp, here's how you could do it with the ssh2 module:

var Connection = require('ssh2');

var ssh = new Connection();
ssh.on('ready', function() {
  ssh.sftp(function(err, sftp) {
    if (err) throw err;
    sftp.fastGet('TestDir/UploadTest.txt',
                 '/cygdrive/c/Users/Administrator/UploadTest.txt',
                 function(err) {
      if (err) throw err;
      ssh.end();
    });
  });
}).connect({
  host: 'test.ftpsite.com',
  port: 22,
  username: 'test',
  password: 'test'
});
user
  • 715
  • 4
  • 13
  • 32
mscdex
  • 104,356
  • 15
  • 192
  • 153
  • ftps is FTP with SSL support, sftp is file transfer using SSH - these are completely different protocols which confusingly similar names. – Steffen Ullrich Apr 28 '14 at 15:57
  • My boss has decided to have me switch to Python for this so I wont be needing Node.js for this part of the project. Thank you though. I had tried using ssh2 before but I wasn't able to get it going (there's not much documentation around) – user Apr 28 '14 at 15:59
  • @SteffenUllrich right, I suggested this solution because he was explicitly using `protocol: 'sftp'` in the original code. FWIW the `ftp` node.js module handles both ftp and ftps. – mscdex Apr 28 '14 at 16:13