Post a reply

Options
Add an Attachment

If you do not want to add an Attachment to your Post, please leave the Fields blank.

(maximum 10 MB; please compress large files; only common media, archive, text and programming file formats are allowed)

Options

Topic review

martin

WinSCP handles the file name correctly, imo.

So it must be the server. Maybe it does not support UTF-8.

Try setting raw session settings Utf to "0" (off).
https://winscp.net/eng/docs/rawsettings

Use $RawSetting parameter of New-WinSCPSession.
rasmus.hvitfeldt

Hi,

Thank you for your reply.

Here is my attached session log, marked as private.
martin

Re: WinSCP powershell script can't handle swedish characters

Please attach a full session log file showing the problem (using the latest version of WinSCP).

To generate log file, set Session.SessionLogPath. Submit the log with your post as an attachment. Note that passwords and passphrases not stored in the log. You may want to remove other data you consider sensitive though, such as host names, IP addresses, account names or file names (unless they are relevant to the problem). If you do not want to post the log publicly, you can mark the attachment as private.
rasmus.hvitfeldt

WinSCP powershell script can't handle swedish characters

Hey,

The background:
I want to download files from a SFTP server and the move the downloaded files to another folder on the SFTP server.

What I've done:
I've used the WinSCP powershell module developed by Thomas Malkewitz (https://github.com/tomohulk/WinSCP). My script looks like this (I've cut some bits out):

$session = New-WinSCPSession -Credential $Credential -Hostname $server -SshHostKeyFingerprint $SSHKey

Try
{
foreach ($file in (Get-WinSCPItem $session -Path $RemoteRootFolder -Filter *.xml)) {
Receive-WinSCPItem -WinSCPSession $session -Path $file.Name -Destination $ServerPath
}

}
Catch
{
$ErrorMessage = $_.Exception.Message
Send-MailMessage -From xxxx@xxxx.se -To xxxx.xxxx@xxxx.se -Subject "Couldn't copy remote file!" -Body "The error message was $ErrorMessage" -SmtpServer mail-server.xxxx.se
}

Try
{
#Move each file in RemoteRootFolder to RemoteOldFolder
foreach ($file in (Get-WinSCPItem $session -Path $RemoteRootFolder -Filter *.xml)) {
Move-WinSCPItem -WinSCPSession $session -Path $file.Name -Destination $RemoteOldFolder

}

The error:
The error message was Exception calling "MoveFile" with "2" argument(s): "Error moving file '/xxxx/LEG?RD-151011230000.xml' to 'xxxx/xxxx/LEG?RD-151011230000.xml'."

The "?" character is actally an "Å" letter, which WinSCP can't seem to handle. Any ideas how I can solve this?

I've talked to Thomas and he told me to post here. :)