运行 使用 WinSCP 的 freeSSHD 服务器上的命令失败 "Your shell is probably incompatible with the application (BASH is recommended)"

Running command on freeSSHD server with WinSCP fails with "Your shell is probably incompatible with the application (BASH is recommended)"

我正在使用下面的脚本来验证远程文件与本地文件的校验和。我机器上安装的服务器是freeSSHd。

当我尝试使用 PowerShell ISE 执行以下脚本时,我收到一条错误消息:

Your shell is probably incompatible with the application (BASH is recommended)

我已在 FreeSSHd 服务器用户属性中授予 shell 访问权限:

脚本:

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 = $True)]
    $localPath,
    [Parameter(Mandatory = $True)]
    $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")
[Reflection.Assembly]::LoadFrom("\c:\Program Files (x86)\WinSCP\WinSCPnet.dll") | Out-Null

# 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 = "bash sha1sum -b $remotePath | awk '{print `}'"

    $result = $session.ExecuteCommand($sha1Command)
    $result.Check()
    $remoteChecksum = $result.Output;
    #$remoteChecksum =
        [System.BitConverter]::ToString($session.CalculateFileChecksum("sha-1", $remotePath))

    # 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

FreeSSHd 服务器不支持任何 "bash"。它的 "shell" 是 Windows cmd.exe.

您的代码无法运行。 Windows cmd.exe 与 WinSCP 不兼容。

而且 FreeSSHd 有很多问题,请不要使用它。


您应该使用另一个 Windows SSH 服务器。

还有很多其他选择。