patrickjuchli / basic-ftp

FTP client for Node.js, supports FTPS over TLS, passive mode over IPv6, async/await, and Typescript.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Question: Does this library support insecure FTP connection?

bosunolanrewaju opened this issue · comments

Describe the bug
When attempting to access an FTP server with plain FTP encryption, the library times out listing files or uploading files to the server.

Example code

ftp.access({
    host: 'host.com',
    port: 21,
    user: 'uSeR',
    password: '',
    secure: false,
})
.then((res) => {
    console.log('running list files', res)
    return ftp.pwd().then(dir => {
        console.log('Current working dir:', dir);
        return ftp.list(dir)
    });
})
.then((res) => console.log(res))
.catch((e) => console.log('Error:', e))
.finally(() => ftp.close())

Console output

Connected to 123.456.789.0:21 (No encryption)
< 220 EFT Login - Friday, 6/16/2023 7:58:39 AM - Please enter valid credentials to continue

Login security: No encryption
> USER uSeR
< 331 Password required for uSeR.

> PASS ###
< 230 Login OK. Proceed.

> FEAT
< 211-Features supported:
 COMB target;source_list
 REST STREAM
 SIZE
 MDTM
 MFMT
 XCRC filename;start;end
 SSCN
 MLST Size*;Modify*;Create;Type*;Unique;Perm*;Lang;Media-Type;CharSet;
 MODE Z 
 XNOP 
 UTF8
 UTF-8
 LANG EN*
 CLNT
211 END

> TYPE I
< 200 Type set to I.

> STRU F
< 202 Command not implemented, superfluous at this site.

> OPTS UTF8 ON
< 

< 200 Entering UTF-8 mode.

> OPTS MLST type;size;modify;unique;unix.mode;unix.owner;unix.group;unix.ownername;unix.groupname;
< 200 MLST OPTS Size;Modify;Type;Unique;

running list files {
  code: 220,
  message: '220 EFT Login - Friday, 6/16/2023 7:58:39 AM - Please enter valid credentials to continue'
}
> PWD
< 257 "/" is current folder.

Current working dir: /
Trying to find optimal transfer strategy...
> EPSV
< 229 Entering Extended Passive Mode (|||12345|)

> PASV
< 227 Entering Passive Mode (123,456,78,901,23,456).

Error: Error: None of the available transfer strategies work. Last error response was 'Error: Timeout when trying to open data connection to 123.456.789.0:1234'.
    at Client.prepareTransfer (/proj/node_modules/basic-ftp/dist/Client.js:700:19)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async Client.list (/proj/node_modules/basic-ftp/dist/Client.js:484:13)

Which version of Node.js are you using?
v16.15.1

Additional context
Sometimes it successfully lists the directories, but that only happened in maybe 1 out of 50 attempts. So I wanted to ask if the plain FTP encryption causes this inconsistent behavior.

The client needs to establish a second connection for any data transfer. That includes directory listings as in the log above. It fails with Error: Timeout when trying to open data connection to 123.456.789.0:1234 which means nothing responds at this address.

These connections are different each time and the require a range of available and accessible ports on the server that holds the FTP server. Could this be the issue? That could explain why it works once in maybe 50 attempts. Is there a firewall?

This is likely not a library issue though. I won't be able to assist you with network configuration issues.

Thank you for the quick response. Please, would you know why this behavior is not consistent with an FTP client like FileZilla? It connects and lists directories successfully. Would FileZilla be able to bypass a firewall if there was one?

It should be able to support plain text connections, yes. I'm not quite sure what's going on here. Which version of basic-ftp have been you using?

Closing due to inactivity. Do reopen if there is new information.