3

I have Node.js app, I'm trying to connect to an FTP server and list the folders/files that are in the FTP server folder.

The server is configured with: TLS/SSL Implicit Encryption

Here's my code:

async function listFilesInFtpFolder() {
  const client = new ftp.Client()
  client.ftp.verbose = true;
  try {
      await client.access({
          host: ftpConfig.host,
          user: ftpConfig.user,
          password: ftpConfig.password,
          port: ftpConfig.port,
          secure: false
      });

      // ********************** NOTE **********************
      // The execution never reaches here, it gets stuck in the 
      // ... previous statement until it times out
      // ********************** NOTE **********************

      console.log('connected');
      console.log(await client.list())

  }
  catch(err) {
      console.log(err)
  }
  client.close()
}

Getting this error:

Listening on port 3001
Connected to 155.66.22.88:6610

Error: Timeout (control socket)
    at Socket.<anonymous> (C:\Dev\my-app\node_modules\basic-ftp\dist\FtpContext.js:296:58)
    at Object.onceWrapper (events.js:298:28)
    at Socket.emit (events.js:209:13)
    at Socket._onTimeout (net.js:468:8)
    at listOnTimeout (internal/timers.js:531:17)
    at processTimers (internal/timers.js:475:7)

The execution never reaches these lines:

      console.log('connected');
      console.log(await client.list())

It gets stuck waiting for the access method until it times out For some weird reason the access method reports "Connected"

Note if I use a program like WinSCP (https://winscp.net/) to connect to this FTP server I'm able to connect and see the folders. But for some weird reason I cannot connect from nodejs. I tried many FTP libraries too.

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
Eric Bergman
  • 1,453
  • 11
  • 46
  • 84
  • Anybody knows why I'm not able to connect? – Eric Bergman Oct 18 '19 at 22:44
  • "The FTP Server is configured with: TLS/SSL Implicit Encryption", but you have set `secure: false` ? – Ben Beri Oct 18 '19 at 22:45
  • @BenBeri Same result whether I set it true or false. Here's the documentation for this property: "(property) AccessOptions.secure?: boolean Use explicit FTPS over TLS. Optional, default is false." – Eric Bergman Oct 18 '19 at 22:50
  • are you sure about the port? – Mohammed naji Oct 18 '19 at 23:24
  • @MohammedNagy Yes 100% sure about the port, as I said if I connect using a program like WinSCP it works fine but for some reason it doesn't work from Node.js I can't figure it out for hte life of me. – Eric Bergman Oct 19 '19 at 00:08
  • Anybody has any idea why this is happening? It's driving me nuts O_o – Eric Bergman Oct 19 '19 at 03:18
  • Can you try to increase the timeout: new ftp.Client(60000)? – Jannes Botis Oct 21 '19 at 15:56
  • @JannesBotis Already tried nothing. – Eric Bergman Oct 22 '19 at 00:18
  • Did u try another ftp library, perhaps like: https://www.npmjs.com/package/ftp They look like they have implicit mode – Ralph Oct 25 '19 at 19:09
  • @Ralph Yes I have but this library hasn't been maintained in over 5 years the master branch is very buggy, many other devs created other Dev branches and fixed some bugs but still it did not work properly for me, I ended up buying a .NET library, created a .NET WebApi app and called it from my Node app – Eric Bergman Oct 25 '19 at 23:48
  • You have a point there... especially if there are vulnerabilities... But it is still highly used and it may be your only option... – Ralph Oct 29 '19 at 21:16

2 Answers2

1

It seems that Node.js does not support implicit TLS/SSL.

See for example:
https://github.com/mscdex/node-ftp/issues/153

Are you sure that your server does not support explicit TLS/SSL?

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
  • Unfortunately I can't control that part, they configured the server with Implicit TLS/SSL, I'm not sure about Node.js Not supporting Implicit TLS/SSL, I don't think Node cares at all, did you mean the library that I was using? – Eric Bergman Oct 20 '19 at 15:10
  • Did you try the explicit mode? – Martin Prikryl Oct 20 '19 at 18:41
  • What exactly did you try? Can you post WinSCP log file? – Martin Prikryl Oct 21 '19 at 05:27
  • The Server is configured in Implicit mode I have no choice but to use Implicit mode. – Eric Bergman Oct 22 '19 at 00:19
  • Do you understand that it's not explicit *or* implicit? That a server can support both modes at the same time? And it is quite unusual for a server to support the implicit mode only? Implicit mode is a non-standard legacy hack that was used decades ago. Only exclicit mode conforms to FTP specification. – Martin Prikryl Oct 22 '19 at 05:12
  • Legacy systems that still use implicity-only still exist and I have to deal with them, I understand it's deprecated but some companies still use that – Eric Bergman Oct 22 '19 at 13:57
  • Sure, that's true. I just wanted to confirm that you actually tested the explicit mode. + I'm afraid that the FTP class you are using does not support the implicit mode. + As the problem is about the "implicit mode", I suggest you state that more prominently in your question - ideally in the question title + And replace the confusing `secure: false` with `true`. – Martin Prikryl Oct 22 '19 at 14:33
  • I also tried with this one which supports implicit mode: (https://github.com/mscdex/node-ftp), I'm able to connect the FTP Server but I cannot list files or upload files to the FTP, it gets stuck in: " File status okay; about to open data connection." – Eric Bergman Oct 22 '19 at 18:50
  • Can you retrieve the listing using any FTP client running on the same machine/same network? – Martin Prikryl Oct 23 '19 at 05:52
  • 1
    I realized almost all FTPS node libraries out there that support implicit are buggy or not maintained properly, I ended up buying an .NET FTP Library works perfectly fine, had to create a separete WebAPI app to call from my Node app – Eric Bergman Oct 25 '19 at 23:45
  • @Eric Bergman Can you tell me what you bought, I'm finding I have the exact same problem. – Motionharvest Jun 08 '20 at 16:44
0

assuming you are using ftp module from npm

according to the document https://www.npmjs.com/package/ftp#methods the secure option accepts mixed type, try 'implicit'

secure - mixed - Set to true for both control and data connection encryption, 'control' for control connection encryption only,

or 'implicit' for implicitly encrypted control connection (this mode is deprecated in modern times, but usually uses port 990) Default: false

Community
  • 1
  • 1
雪 霁
  • 11
  • 4