Powershell UTF8 paths in GetFiles

Advertisement

robin.k
Guest

Powershell UTF8 paths in GetFiles

Hello,
I'm using the example from https://winscp.net/eng/docs/library_session_getfiles in a powershell script to download files from a sftp server.
It works fine if the paths used in GetFiles() don't contain anything else than ASCII characters. If I create a directory on the server that contains german umlauts or chinese Han characters, I get a "No such file or directory" error.

Error with umlaut:
Error: Error listing directory '/Aufträge'.
No such file or directory.
Error code: 2
Error message from server: No such file

Error with han character:
Error: Error listing directory '/ä»S'.
No such file or directory.
Error code: 2
Error message from server: No such file

GetFiles Call:
$transferResult = $session.GetFiles("/Aufträge/*", "D:\Aufträge\", $False, $transferOptions)
It does neither work with source nor with destination path.
It looks like the strings are converted to ascii at some point. Does anyone know how to use UTF8 paths in powershell?

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
40,476
Location:
Prague, Czechia

Please attach WinSCP session log file both from PowerShell and GUI.

Though chances are that GUI was able to autodetect that the server fails to use UTF-8 encoding for files, while GUI is retrieving an initial directory listing. But .NET assembly does do any initial listing (unless you ask for it).
See https://winscp.net/eng/docs/faq_utf8#sftp

Reply with quote

robin.k
Guest

I just figured it out. Thanks for your help martin, the session log lead me to right google searches. :)
My powershell script was encoded in UTF8, after reencoding it in UTF8-BOM (with Notepad++) the parameters are passed correctly, and the download works as intended.

Reply with quote

Advertisement

You can post new topics in this forum