Downloading UTF-8 filenames from an FTP-server that does not support them, with System.Net.FtpWebRequest

I have written a windows service in .Net that monitors an FTP location for new files, which it then downloads to a local folder for processing. To be precise, the tool first renames the file before downloading it. It uses the .Net standard FtpWebRequest class from System.Net. Every once in a while, a file could not be downloaded, and the FtpResponse would be 550 – Action not taken, file unavailable. This happened especially if the file name had “special characters” in it, one example being a file named ANDRÉ.XML. The workaround was simple: I’d launch an FTP application, rename the file to ANDRE.XML, and it would quickly be picked up by my tool again.

It bothered me that somehow the FTP application was able to rename the file, while FtpWebRequest was not. (It also bothered me that every once in a while I had to fix a stuck file like this, but let’s not go down that road here.) So I attached a trace log to see what was going on.
Lees meer over dit bericht


Implementing IEquatable is not enough to use a class as a Dictionary key

Note to future self: it is not enough to implement IEquatable<T> to use a class as a Dictionary key.

Today I needed a Dictionary with a composite key, a combination of several values. So I quickly cooked up a class with public properties to cover the values and for ease of use, a constructor to quickly set those values. But to be able to use it as a dictionary key, I would need a little more. Per default, classes are only checked for reference equality, which makes sense. But I would need to have the system evaluate two separate instances of this class as equal, if all of their properties were equal. Lees meer over dit bericht