I am using the following commands to calculate the checksums:
$remoteChecksumBytes = $session.CalculateFileChecksum("md5", $remoteFilePath)
$remoteChecksum = [System.BitConverter]::ToString($remoteChecksumBytes)
The first command gets an incorrect checksum returned by the server (identical value) for any file with a space in it's name. The
$session.CalculateFileChecksum
function sends the
XMD5
command with the file name in quotes if the filename or path has a space in it's name. If the path or filename does not have any spaces in it, it sends it correctly without quotes. The quotes seem to be the problem in the
XMD5
command generated by
$session.CalculateFileChecksum()
.
I was unaware of
$session.ExecuteCommand
function you suggested so I used that as follows for a test:
$rcmd = "XMD5 " + $RootDirName + "/1 plusdelta-perceptions.pdf"
$session.ExecuteCommand($rcmd).Check()
And the WinSCP.log shows the following:
. Script: call XMD5 TEST/1 plusdelta-perceptions.pdf
. 2022-10-13 11:40:24.738 Executing user defined command.
> 2022-10-13 11:40:24.738 XMD5 TEST/1 plusdelta-perceptions.pdf
< 2022-10-13 11:40:25.703 Script: 251 "TEST/1 plusdelta-perceptions.pdf" 556D7E4AFC364DFE5D6D6B04B03312E0
As you can see, the
XMD5
is generated without quotes and the server returns the correct checksum.
Wouldn't this imply a bug in the
$session.CalculateFileChecksum
function of WINSCP .NET Assembly?