Bug in CalculateFileChecksum function?

Advertisement

RexS
Joined:
Posts:
4

Bug in CalculateFileChecksum function?

I'm using the latest WinSCP .NET Assembly and PowerShell 7 and seem to get the wrong MD5 checksum returned if the filename has any spaces in it. My remote system is Box.com data and I'm downloading files then checking the MD5 checksum of both local and remote files.
In fact, any file that has spaces in it's name on Box returns the exact same MD5 check sum of D41D8CD98F00B204E9800998ECF8427E. If I copy the file on Box and remove the spaces in the name, the MD5 is calculated correctly as returned from the server and for the local file that was copied.

Client code:
$remoteChecksumBytes = $session.CalculateFileChecksum("md5", $remoteFilePath)
Below is the WinSCP log and you can see quotes are shown for files with spaces in first line and double quotes on the second line. If the file name does not have spaces, the log shows no quotes at all.
> 2022-10-07 16:47:46.620 XMD5 "/TEST/1 perceptions.pdf"
< 2022-10-07 16:47:46.669 251 ""/TEST/1 perceptions.pdf"" D41D8CD98F00B204E9800998ECF8427E
 
> 2022-10-07 16:47:50.112 XMD5 "/TEST/Joe Smith.pdf"
< 2022-10-07 16:47:50.160 251 ""/TEST/Joe Smith.pdf"" D41D8CD98F00B204E9800998ECF8427E
Any ideas where this is doing wrong?

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
40,605
Location:
Prague, Czechia

Re: Bug in CalculateFileChecksum function ?

Why do you think it's WinSCP's bug? Isn't it rather server's bug? Or do you believe the quotes are the problem? Did you try sending the XMD5 command to the server without the quotes? Would the server return correct checksum then?

Reply with quote

RexS

Re: Bug in CalculateFileChecksum function ?

I'm not certain where the bug is. I'm using the API which generates the XMD5 command so I suspected that may be where the error is and possibly related to the quotes. How would I send the XMD5 command directly with WinSCP? I can't install another FTPS client and need secure TLS support minimum.

Reply with quote

RexS
Joined:
Posts:
4

Re: Bug in CalculateFileChecksum function ?

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?

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
40,605
Location:
Prague, Czechia

Re: Bug in CalculateFileChecksum function ?

I agree that in general the FTP way is not to quote. But XMD5 command is not a standard, so there's really no specification about its argument format. The servers I've tested the XMD5 implementation against either required the quotes or didn't care. That's why WinSCP uses the quotes. Your server is the first one that requires not to quote. Though I find it strange that with quotes, the server, instead of retunring an error, returns some checksum. That on the other hand looks like a bug in the server.

Anyway, I can try to make WinSCP compatible with your server. Can you post a session log file, so I can check how to identify your specific server?

Reply with quote

Advertisement

You can post new topics in this forum