1

I am trying to connect to Secured FTP server using package "ftp"

When i connect to not secured server code works fine and all events got raised without issues and i see a content.

But as long as i am trying to connect to server with acc and password, none of the event are getting raised and nothing in console logs (no errors), server just keep running.

I tried multiple ports, and 22 is correct one, because on other ports it error out on startup.

I tried secure: true/false and it didn't helped me.

const Client = require("ftp");
const fs = require("fs");

let config = {
  host: "10.2.22.22",
  user: "test",
  password: "pass",
  port: 22
};

var c = new Client();
c.on("ready", function() {
  c.list(function(err, list) {
    if (err) throw err;
    console.dir(list);
    c.end();
  });
});
c.on("greeting", function() {
  console.log("greeting");
});
c.on("close", function() {
  console.log("close");
});
c.on("end", function() {
  console.log("end");
});

c.connect(config);

This is all console output which does not change:

Mac | util-> nodemon ftpUpload.js 
[nodemon] 1.18.7
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: *.*
[nodemon] starting `node ftpUpload.js`

After some timeout i noticed that

end
close

Got fired but nothing else. Does anyone knows where is the issue?

Anton
  • 1,344
  • 3
  • 15
  • 32
  • 1
    I believe this is a bug with this package. I was having event issues with it as well so I switched to [basic-ftp](http://npmjs.com/package/basic-ftp) Issue: https://github.com/mscdex/node-ftp/issues/234 – Get Off My Lawn Jul 01 '19 at 20:49

1 Answers1

2

Port 22 is the default port for SSH. You can transfer files over SSH using the SFTP protocol.

SFTP is not the same as FTP (nor is it the same as FTPS (which is FTP + SSL or TLS).

You need to use a module that supports SFTP such as ssh2.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
  • But how using this package i can upload or download files? I don't see those in documentation. – Anton Jul 01 '19 at 21:01
  • Quote: sftp(< mixed >accept, < mixed >reject) - The client has requested the SFTP subsystem. accept and reject are functions if the client requested a response. accept() returns an SFTPStream in server mode (see the SFTPStream documentation for details). – Quentin Jul 01 '19 at 21:04