Differences
This shows you the differences between the selected revisions of the page.
2016-04-29 | 2016-05-25 | ||
error: prefix (martin) | logging (martin) | ||
Line 17: | Line 17: | ||
<code powershell - VerifyFileChecksum.ps1> | <code powershell - VerifyFileChecksum.ps1> | ||
# @name Verify &Checksum | # @name Verify &Checksum | ||
- | # @command powershell.exe -ExecutionPolicy Bypass -File "%EXTENSION_PATH%" -sessionUrl "!S" -localPath "!^!" -remotePath "!/!" -pause | + | # @command powershell.exe -ExecutionPolicy Bypass -File "%EXTENSION_PATH%" -sessionUrl "!S" -localPath "!^!" -remotePath "!/!" -pause -sessionLogPath "%SessionLogPath%" |
# @description Compares checksums of the selected local and remote file | # @description Compares checksums of the selected local and remote file | ||
# @flag RemoteFiles | # @flag RemoteFiles | ||
- | # @version 1 | + | # @version 2 |
+ | # @homepage ~~SELF~~ | ||
+ | # @require WinSCP 5.8.3 | ||
+ | # @option SessionLogPath file "&Session log file:" | ||
+ | · | ||
param ( | param ( | ||
# Use Generate URL function to obtain a value for -sessionUrl parameter. | # Use Generate URL function to obtain a value for -sessionUrl parameter. | ||
Line 29: | Line 32: | ||
[Parameter(Mandatory)] | [Parameter(Mandatory)] | ||
$remotePath, | $remotePath, | ||
+ | $sessionLogPath = $Null, | ||
[Switch] | [Switch] | ||
$pause = $False | $pause = $False | ||
) | ) | ||
+ | · | ||
try | try | ||
{ | { | ||
Write-Host $localPath | Write-Host $localPath | ||
+ | · | ||
# Calculate local file checksum | # Calculate local file checksum | ||
$sha1 = [System.Security.Cryptography.SHA1]::Create() | $sha1 = [System.Security.Cryptography.SHA1]::Create() | ||
$localStream = [System.IO.File]::OpenRead($localPath) | $localStream = [System.IO.File]::OpenRead($localPath) | ||
$localChecksum = [System.BitConverter]::ToString($sha1.ComputeHash($localStream)) | $localChecksum = [System.BitConverter]::ToString($sha1.ComputeHash($localStream)) | ||
+ | · | ||
Write-Host $localChecksum | Write-Host $localChecksum | ||
Line 51: | Line 55: | ||
$sessionOptions = New-Object WinSCP.SessionOptions | $sessionOptions = New-Object WinSCP.SessionOptions | ||
$sessionOptions.ParseUrl($sessionUrl) | $sessionOptions.ParseUrl($sessionUrl) | ||
+ | · | ||
$session = New-Object WinSCP.Session | $session = New-Object WinSCP.Session | ||
+ | · | ||
try | try | ||
{ | { | ||
+ | $session.SessionLogPath = $sessionLogPath | ||
+ | |||
# Connect | # Connect | ||
$session.Open($sessionOptions) | $session.Open($sessionOptions) | ||
Write-Host $remotePath | Write-Host $remotePath | ||
+ | · | ||
# Calculate remote file checksum | # Calculate remote file checksum | ||
$remoteChecksum = [System.BitConverter]::ToString($session.CalculateFileChecksum("sha-1", $remotePath)) | $remoteChecksum = [System.BitConverter]::ToString($session.CalculateFileChecksum("sha-1", $remotePath)) | ||
Line 70: | Line 76: | ||
$session.Dispose() | $session.Dispose() | ||
} | } | ||
+ | · | ||
# Compare cheksums | # Compare cheksums | ||
if ($localChecksum -eq $remoteChecksum) | if ($localChecksum -eq $remoteChecksum) | ||
Line 88: | Line 94: | ||
$result = 1 | $result = 1 | ||
} | } | ||
+ | · | ||
# Pause if -pause switch was used | # Pause if -pause switch was used | ||
if ($pause) | if ($pause) | ||
Line 95: | Line 101: | ||
[System.Console]::ReadKey() | Out-Null | [System.Console]::ReadKey() | Out-Null | ||
} | } | ||
+ | · | ||
exit $result | exit $result | ||
</code> | </code> | ||