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