Thomas
Thomas

Reputation: 2984

FTP files from folders that have international characters/mutations/vowels (ä. ö. ü) with Windows FTP in batch-file

I'm trying to create a batch file that uploads files to an FTP server. It all works fine except for one specific folder which has mutations/vowels in its name (can't change that. Aka the folders name has an ö inside. ).

My question here is: What options exist to achieve this?

Example for the ftp batch file (UTF-8 encoding):

cd C:\uplaodfiles\ländle\*
ftp -n -s:C:\test\UploadTest.ftp

Example for the loaded file:

open meimei
user meiuser meipassword
pasv
bin
cd uploaddir
prompt
mput c:\uploadfiles\ländle\*
close
bye

It all works until the mput where the ftp tries to convert the ä into special characters that the local drive naturally does not find.

As additional note: I start out in the c:\test folder on the command line as the UploadTest.bat file is located there.....even though I use cd. thus if I use mput without parameters (or with only * given) it is still c:\test which he copies.

Edit:

The output from a run (I cut out the non important parts..... pasv fails btw. No clue why? Had showed it previously so I'm leaving that part out).

ftp> BIN
200 Command okay.
ftp> cd uploaddir
250 CWD command successful.
ftp> prompt
Interaktivmodus AUS .              <-- interactive mode off
ftp> mput C:\L├ñndle\*             <-- should be Ländle
C:\Ländle\*:Datei nicht gefunden  <-- file not found
ftp> close
221 Service closing control connection.
ftp> bye

As a bit of it is in German I've put in translations where necessary with <--

Upvotes: 5

Views: 3897

Answers (3)

Newton
Newton

Reputation: 1

I had the same problem. My batch file is generated by a VBScript, and its coded in UTF-8. The solution was converting the file to ANSI. You can try converting your batch and testint. If it works, you can use the code in https://www.vbsedit.com/scripts/misc/text/utf8_ansi.asp

Upvotes: 0

Martin Prikryl
Martin Prikryl

Reputation: 202360

It works, as long as the UploadTest.ftp is either

  • in UTF-8 encoding (with or without BOM) – Windows 10 only (didn't test Windows 8)
  • in ANSI encoding that matches the Windows "Language for non-Unicode programs" and the characters in the file name are contained in the ANSI encoding – Windows 7 and 10

The UTF-8 in batch files does not seem to be supported (both in Windows 7 and Windows 10). So you cannot do the cd there (unless in the default legacy ANSI encoding).


If you need a UTF-8 solution for Windows 7, you probably have to use another FTP client.

For example with WinSCP scripting:

  • Batch file:

    winscp.com /log=UploadTest.log /script=UploadTest.ftp
    
  • Upload script (UploadTest.ftp) in UTF-8 encoding with BOM:

    open ftp://meiuser:meipassword@meimei/
    cd uploaddir
    put c:\uploadfiles\ländle\*
    exit
    

See the guide for Converting Windows FTP script to WinSCP script.

(I'm the author of WinSCP)

Upvotes: 3

Olli
Olli

Reputation: 375

Perhaps Microsoft has updated ftp.exe? But my experiences are somewhat different from those of @Martin Prikryl:

  • Windows 10 (1903): UploadTest.ftp can be UTF-8 encoded, with or without BOM
  • Windows 7: UploadTest.ftp can be UTF-8 encoded, BOM must not exist
  • Windows XP (!): UploadTest.ftp can be UTF-8 encoded, BOM must not exist

Tested with characters ä, ö, ü, and ᚠ.

Edit 1: The alternative to UTF-8 is an ASCII file encoded with ANSI codepage (ACP) but not OEM codepage (OEMCP) of the machine.

Edit 2: If you want to use stdout of the ftp.exe process, the encoding of stdout has to be ASCII with OEM codepage (tested unter Windows 10 only)! What a typical MS mess!

Upvotes: 0

Related Questions