WinSCP powershell script can't handle swedish characters

Advertisement

rasmus.hvitfeldt
Joined:
Posts:
4

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. :)

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
41,517
Location:
Prague, Czechia

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.

Reply with quote

Advertisement

You can post new topics in this forum