Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

batch-file

ftp

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 <--

like image 580
Thomas Avatar asked Oct 19 '22 00:10

Thomas


1 Answers

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)

like image 86
Martin Prikryl Avatar answered Oct 26 '22 22:10

Martin Prikryl