icetee / node-ftp

An FTP client module for node.js
MIT License
25 stars 16 forks source link

Fixed rmdir operation with recursion on non-existent directory #20

Open Marv-CZ opened 3 years ago

Marv-CZ commented 3 years ago

When you call rmdir() with recursive=true on a non-existent directory it causes:

TypeError: Cannot read property '0' of undefined at deleteNextEntry (/opt/noderedftp/lib/node_modules/node-red/nodes/extra/ftp/node_modules/@icetee/ftp/lib/connection.js:808:21) at /opt/noderedftp/lib/node_modules/node-red/nodes/extra/ftp/node_modules/@icetee/ftp/lib/connection.js:830:5 at final (/opt/noderedftp/lib/node_modules/node-red/nodes/extra/ftp/node_modules/@icetee/ftp/lib/connection.js:515:11) at Object.cb (/opt/noderedftp/lib/node_modules/node-red/nodes/extra/ftp/node_modules/@icetee/ftp/lib/connection.js:552:11)

rmdir() calls list() which returns "No such file or directory" string instead a error and rmdir() tries to use it as a dir item.

I have replaced list() with listSafe() which is able to return the error, but it has bug too. It doesn't test missing optional arguments. So this patch also solves this issue.

Marv-CZ commented 3 years ago

I found out it's not general problem, but only ftpd server from busybox which I used for testing.

Marv-CZ commented 3 years ago

For non-existent dirname:

BusyBox ftpd LIST dirname returns data "dirname: No such file or directory" and "226 Transfer complete" list('dirname', cb) returns [ 'dirname: No such file or directory' ] rmdir('dirname', true, cb) produces TypeError

Pure-FTPD LIST dirname returns empty data and "226 0 matches total" list('dirname', cb) returns [] rmdir('dirname', true, cb) returns error

ProFTPD LIST dirname returns "450 dirname: No such file or directory" list('dirname', cb) returns error with message "dirname: No such file or directory" rmdir('dirname', true, cb) returns error