'"No such file or directory" when synchronizing a local file with percent sign to remote directory with WinSCP

I have file with name %253csvg%2fonload=alert(1)%253e.jpg-131x94

I am trying to sync the files to remote server using WinSCP .NET assembly Session.SynchronizeDirectories

I am getting error

"No such file or directory"

But I see the file name in the error is %3csvg/onload=alert(1)%3e.jpg-131x94 some few of the words are missing.

I am using WinSCP 5.9.6 product version.

$FTPSourceFolder = "D:\...\00"
$FTPDestionationFolder = "/storage/../00"

$synchronizationResult = $session.SynchronizeDirectories(
    [WinSCP.SynchronizationMode]::Remote, $FTPSourceFolder,$FTPDestionationFolder, $True, $False) 
$synchronizationResult.check()  


Solution 1:[1]

WinSCP will by default URL-decode the local file name.

If you do not want that, you can turn this feature off:

$transferOptions = New-Object WinSCP.TransferOptions
$transferOptions.AddRawSettings("ReplaceInvalidChars", "0")
$synchronizationResult =
    $session.SynchronizeDirectories(
        [WinSCP.SynchronizationMode]::Remote, 
        $FTPSourceFolder,$FTPDestionationFolder, $True, $False,
        $transferOptions)

References:

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1