Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Connect to FTP server with TLS/SSL Implicit Encryption in Node.js

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.

like image 673
Eric Bergman Avatar asked Dec 11 '25 02:12

Eric Bergman


1 Answers

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?

like image 189
Martin Prikryl Avatar answered Dec 13 '25 17:12

Martin Prikryl



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!