Post a reply

Options
Add an Attachment

If you do not want to add an Attachment to your Post, please leave the Fields blank.

(maximum 10 MB; please compress large files; only common media, archive, text and programming file formats are allowed)

Options

Topic review

RexS

Re: Bug in CalculateFileChecksum function ?

It's box.com and you can create a free account for testing and use ftp.box.com.
martin

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?
RexS

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?
martin

Re: Bug in CalculateFileChecksum function ?

Can you explain more about "I'm using the API which generates the XMD5 command"?

To send a literal command to the server, use Session.ExecuteCommand method.
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.
martin

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?
RexS

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?