I'm encountering an issue when using the basic-ftp library in Node.js to connect to a Pure-FTPd server. The connection and file listing work fine, but when I attempt to download a file using downloadTo, I receive the following error:
Error: Server sent FIN packet unexpectedly, closing connection.
at Socket.<anonymous> (/home/schemannkurier/api/sk_backend/node_modules/basic-ftp/dist/FtpContext.js:129:56)
at Socket.emit (node:events:526:35)
at Socket.emit (node:domain:488:12)
at endReadableNT (node:internal/streams/readable:1589:12)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
FTP Session:
Connected to 192.168.179.71:21 (No encryption)
< 220---------- Welcome to Pure-FTPd [TLS] ----------
... (server welcome message)
> OPTS UTF8 ON
< 200 OK, UTF-8 enabled
... (login and feature negotiation)
> PASV
< 227 Entering Passive Mode (192,168,179,71,182,86)
> RETR /schemannkurier/Gutschein_Example.odt
< 150-Accepted data connection
150 63.4 kbytes to download
Downloading from 192.168.179.71:46678 (No encryption)
> QUIT
Error: Server sent FIN packet unexpectedly, closing connection.
... (more details in the error message)
Code:
const ftp = require("basic-ftp");
const FTPclient = new ftp.Client();
async function connectFTP() {
try {
FTPclient.ftp.verbose = true;
await FTPclient.access({
host: "192.168.179.71",
user: "admin",
password: "******", // (masked for security)
port: 21,
secure: false
});
console.log(await FTPclient.list());
await FTPclient.downloadTo("/home/schemannkurier/Documents/skbackend/otheruploads/Gutschein_Example.odt", "/schemannkurier/Gutschein_Example.odt");
} catch (err) {
console.log(err);
}
}
connectFTP();
**Additional Details: ** Node.js version: 20.10.0 FTP server: Pure-FTPd [TLS] Using the basic-ftp library for FTP interactions.
I've tried troubleshooting, but I'm unable to pinpoint the cause of the "Server sent FIN packet unexpectedly" error. Any insights or suggestions on resolving this issue would be greatly appreciated. Thank you!
You don't have to connect in nodejs by FTP to the nas server, you can also mount thr nas server by smb to a specific path and than you can reach the files of the nas server on the path, where you mounted the smb sharing.