您可以将私钥嵌入到PowerShell WinSCP脚本中,而不是调用.ppk文件吗? 也许是这样的?
# Load WinSCP .NET assembly
Add-Type -Path "WinSCPnet.dll"
# Set up session options
$sessionOptions = New-Object WinSCP.SessionOptions -Property @{
Protocol = [WinSCP.Protocol]::Scp
HostName = "domain.com"
UserName = "username"
SshHostKeyFingerprint = "ssh-rsa 2048 38741934871934871293471293487"
SecurePrivateKeyPassphrase = "AAABAHH1......................"
}
$session = New-Object WinSCP.Session
try
{
# Connect
$session.Open($sessionOptions)
# Your code
}
finally
{
$session.Dispose()
}
使用SessionOptions.SshPrivateKey
属性:
$sessionOptions = New-Object WinSCP.SessionOptions -Property @{
...
SshPrivateKey = "PuTTY-User-Key-File-3: ssh-rsa
Encryption: none
Comment: ...
Public-Lines: 6
...
Private-Lines: 14
...
Private-MAC: ...
"
}
# Set up session options
$session = New-Object WinSCP.Session
# Connect
$session.Open($sessionOptions)