简体   繁体   English

无法使用npm中的“ ftp”包连接到ftp服务器

[英]Not able to connect to ftp server using “ftp” package from npm

I am trying to connect to Secured FTP server using package "ftp" 我正在尝试使用软件包“ ftp”连接到安全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. 但是,只要我尝试使用acc和密码连接到服务器,就不会触发任何事件,并且控制台日志中也不会出现任何错误(无错误) ,服务器只会继续运行。

I tried multiple ports, and 22 is correct one, because on other ports it error out on startup. 我尝试了多个端口,其中22个是正确的端口,因为在其他端口上,启动时会出错。

I tried secure: true/false and it didn't helped me. 我尝试使用secure: true/false ,但并没有帮助我。

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? 有人知道问题出在哪里吗?

Port 22 is the default port for SSH. 端口22是SSH的默认端口。 You can transfer files over SSH using the SFTP protocol. 您可以使用SFTP协议通过SSH传输文件。

SFTP is not the same as FTP (nor is it the same as FTPS (which is FTP + SSL or TLS). SFTP与FTP不同(也与FTPS(FTP + SSL或TLS)相同)。

You need to use a module that supports SFTP such as ssh2 . 您需要使用支持SFTP的模块,例如ssh2

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM