FubarDevelopment / FtpServer

Portable FTP server written in .NET
http://fubardevelopment.github.io/FtpServer/
MIT License
474 stars 161 forks source link

FtpCommandCollector does not work correctly with windows-1251 encoding #33

Closed kobtsev closed 6 years ago

kobtsev commented 6 years ago

It appears when filenames contain cyrillic characters. Unit-test for explain:

// Copyright, etc...

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Xunit;

namespace FubarDev.FtpServer.Tests
{
    public class FtpCommandCollectorTests
    {
        [Fact]
        public void TestWithWindows1251Encoding()
        {
            var encoding = Encoding.GetEncoding(1251) // Encoding.Default;
            var collector = new FtpCommandCollector(() => encoding);

            const String cyrillicSymbols = "абвгдеёжзийклмнопрстуфхцчшщыъьэюя";

            var expectedCommands = new[] {new FtpCommand("TEST", cyrillicSymbols)};

            var stringToTest = String.Format("TEST {0}\r\n", cyrillicSymbols);
            var actualCommands = Collect(collector, stringToTest).ToArray();

            // Test failed
            // TELNET: Unknown command received - skipping 0xFF
            // 0xFF == 'я' (maybe?)
            Assert.Equal(expectedCommands, actualCommands, new FtpCommandComparer());
            Assert.True(collector.IsEmpty);
        }

        // Collect, FtpCommandComparer, etc...
    }
}
fubar-coder commented 6 years ago

FTP uses "Telnet strings" which means, that the \u00FF character has a special meaning (Telnet Protocol Specification, RFC 854) and has to be escaped (i.e. sent twice).

I updated the code and will release the 2.1 version soon. If your client doesn't send the 0xFF character twice, then I'd suggest using a different client or creating a workaround in the FTP server.