Win32 API. The FtpGetFileW function does not work with non-English letters.

Participant 41 Reputation points
2024-07-14T12:31:17.7766667+00:00

What should a programmer do to extract a file from the Internet using FTP that has non-English letters in its name?

Are there any Win32 API functions (maybe Socket functions) that can be used instead of FtpGetFileW?

I am interested in low-level programming, not the capabilities of C++, C# and other programming languages.

Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,511 questions
{count} votes

3 answers

Sort by: Most helpful
  1. Jeanine Zhang-MSFT 9,431 Reputation points Microsoft Vendor
    2024-07-15T02:31:04.8133333+00:00

    Hello,

    Welcome to Microsoft Q&A!

    The FtpGetFileW function does not work with non-English letters.

    Th reason is that FTP is a rather old protocol, according to RFC 854, the NVT requires the use of (7-bit) ASCII as the character set.

    In order to support non-English characters, the FTP specifications were extended in 1999 in RFC 2640.

    If you use non-English characters without using RFC 2640 compatible software, there will be problems--problems which are entirely self-made by not obeying the specifications.

    Are there any Win32 API functions (maybe Socket functions) that can be used instead of FtpGetFileW?

    There is no better way to extract a file from an FTP server.

    Thank you.

    Jeanine


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


  2. Castorix31 83,101 Reputation points
    2024-07-15T11:47:43.0066667+00:00

    FTP command works with non-English letters (I tested a script as explained at https://www.jscape.com/blog/using-windows-ftp-scripts-to-automate-file-transfers , with get instead of put, with a file name containing chinese characters)

    So it can be launched with ShellExecute for example or by using Winsock (RETR command)

    As I saw it used RtlUnicodeToUTF8N, I tested with Winsock and it worked with the same file, like

    WCHAR UnicodeStringSource[260] = L"RETR /htdocs/測試文件.txt\r\n";

    (then RtlUnicodeToUTF8N, send command, ...)

    0 comments No comments

  3. Darran Rowe 561 Reputation points
    2024-07-16T00:43:00.6866667+00:00

    The W functions will convert based upon your process' current codepage. So it is using Windows-1251 because your system is set to Windows-1251.

    The two options that you have are:

    1. Set Windows to UTF-8
    2. Manifest your application to use UTF-8

    Use UTF-8 code pages in Windows Apps goes into this and it requires Windows 10 1903 or newer.