문제

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.

도움이 되었습니까?

해결책

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'
});
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top