Verifying Checksum - Operation Not Supported

Advertisement

CptPicard
Joined:
Posts:
2
Location:
Earth

Verifying Checksum - Operation Not Supported

Hello! I just switched to WinSCP after seeing this post in your documentation about verifying checksums. But I'm having a problem with it. :(

When I run the custom command, it gets to the "# Calculate remote file checksum" stage, and then returns an error "Operation not supported."


As far as I can tell, I've got everything setup right - is there anything I need to change on the server to make this compatible? Or is there an easy way to swap out the server command to run "sha1sum TARGET" on the shell and return that result?

Thanks for any assistance you can offer!


Additional information:

The server is Ubuntu 14.04, and I'm connected via SFTP. The user in the sessionUrl has full shell access.

I'm using the latest version of both WinSCP and the WinSCP .NET assembly. I've got the script in the same folder as the assembly, I've unblocked the files, and I've edited the script with my session URL. And I've got it in my custom commands of course.

Reply with quote

CptPicard
Joined:
Posts:
2
Location:
Earth

I see that the script didn't work because vsftpd didn't support the checksum protocol. Oh well!

I hacked together a script that works for me on Windows 8 (and an Ubuntu 14.04 server), hopefully it'll help anyone else looking to do the same thing.

https://gist.github.com/Ineluctable/20b370d78ea025ceabd2

Code posted here for posterity:

param (
    # Use Generate URL function to obtain a value for -sessionUrl parameter.
    $sessionUrl = "sftp://user:mypassword;fingerprint=ssh-rsa-xx-xx-xx@example.com/",
    [Parameter(Mandatory)]
    $localPath,
    [Parameter(Mandatory)]
    $remotePath,
    [Switch]
    $pause = $False
)
 
try
{
    Write-Host $localPath -foregroundcolor Gray
 
    # Calculate local file checksum
    $localChecksum = ((CertUtil -hashfile $localPath SHA1)[1] -replace " ","")
 
    # Write-Host "Local Checksum:"
    Write-Host $localChecksum
    
    # Load WinSCP .NET assembly
    Add-Type -Path (Join-Path $PSScriptRoot "WinSCPnet.dll")
 
    # Setup session options
    $sessionOptions = New-Object WinSCP.SessionOptions
    $sessionOptions.ParseUrl($sessionUrl)
 
    $session = New-Object WinSCP.Session
 
    try
    {
        # Connect
        $session.Open($sessionOptions)
        
        Write-Host $remotePath -foregroundcolor Gray
 
        # Calculate remote file checksum
        $sha1Command = "sha1sum -b $remotePath | awk '{print `$1}'"

        $result = $session.ExecuteCommand($sha1Command)
        $result.Check()
        $remoteChecksum = $result.Output;
        
        # Write-Host "Remote Checksum:"
        Write-Host $remoteChecksum
    }
    finally
    {
        # Disconnect, clean up
        $session.Dispose()
    }
 
    # Compare cheksums
    if ($localChecksum -eq $remoteChecksum)
    {
        Write-Host
        Write-Host "Match" -foregroundcolor "green"
        $result = 0
    }
    else
    {
        Write-Host
        Write-Host "Does NOT match" -foregroundcolor "red"
        $result = 1
    }
}
catch [Exception]
{
    Write-Host $_.Exception.Message
    $result = 1
}
 
# Pause if -pause switch was used
if ($pause)
{
    Write-Host "Press any key to exit..."
    [System.Console]::ReadKey() | Out-Null
}
 
exit $result

Reply with quote

Advertisement

You can post new topics in this forum