fixing an issue in ftp-srv
when the strange bug isn't your fault!
by nova - 03/31/26, 06:55 AM
428 words ( 3 min to read)
For some background, I've spent the past few months working on FolderHarbor - a powerful, multi-protocol file system. Now that I am nearing completion of the main server, I decided I wanted to add more protocols to it. FTP was one of these, so I started searching for a Node.JS library that could help.
ftp-srv
In my searching, I found out about ftp-srv. This seemed like my best option, and the implementation patterns weren't too wildly different to the work I had done implementing WebDAV before. I started implementing it, then locked my computer and went to sleep.
A few days later, at around midnight (with a Palm Beach Rebel in hand), I decided to continue my work. I wrote a bunch of code to connect the library to my ACL system and add audit logging.
The Issue
Dolphin is KDE's file manager, and it can connect to FTP servers directly. I use KDE Plasma on my desktop, so I have been using Dolphin to test FolderHarbor's various providers (as well as Finder on my MacBook Air). I logged into the FolderHarbor FTP integration and started trying different operations. Everything was working: I could navigate directories, open and edit files, and create new files. However, when I tried opening an empty file, I got an error: "The file ftp://test@localhost:2100/home/nova/Desktop/abc.txt could not be loaded, as it was not possible to read from it. Check if you have read access to this file."
Patching
I decided to get WireShark, after searching a bit about how to read FTP traffic. I also tested a little with lftp in debugging mode, and they both showed the same thing: the server was responding with 213 File status when called on an empty file, instead of the number of bytes (say, if called on a file that had "test" in it, it responded with 213 5). This was causing KDE programs issues when they tried to read empty files, and was the root of my problem.
Now knowing the issue, I used PNPM patching to edit the SIZE command to return 213 0 for empty files. The patch itself was a simple one-liner, but finding this took an hour or so of debugging. Now, it returns the correct data, and KDE programs can interact with empty files properly!
Closing
That's the whole post, it's a shorter one today! :3
I planned to make a pull request with my patch, however the ftp-srv library has many un-merged pull requests and generally isn't being updated from what I can tell. I still might do it, just am not worrying about it right now.