我想通过WinShell中的powerShell保存会话,但是我无法使用以下代码保存任何会话。可能是PowerShell代码对于保存会话是错误的。我想保存会话,每当我打开WinSCP时,我都可以看到该会话并能够登录。下面是代码快照:
try
{
# Load the assembly and setup the session properties
Add-Type -Path "C:\Program Files (x86)\WinSCP\WinSCPnet.dll"
# Session setup options
$sessionOptions = New-Object WinSCP.sessionOptions -Property @{
Protocol = ([WinSCP.Protocol]::Sftp)
HostName = "xxx.cloud.com"
UserName = "sftpuser_WIN_NPD"
PortNumber = "40022"
#Password = ""
SshPrivateKeyPath = "C:\key\sftp_private.ppk"
SshHostKeyFingerprint = "ssh-rsa 2048 0c:ce:5a:8a:82:f6:03:xx:xx:xx:xx:xx:xx:xx:xx:xx"
}
$session = New-Object WinSCP.session
}
catch
{
Write-Host "Error : $($_.Exception.Message)"
exit 1
}
请帮助我,在此先感谢:)
您不能使用WinSCP .NET程序集为WinSCP GUI创建存储的站点。
您必须在Windows注册表(或INI文件)中创建站点密钥。参见https://winscp.net/eng/docs/config
一个简单的例子:
$key = New-Item 'HKCU:\Software\Martin Prikryl\WinSCP 2\Sessions\My New Session' -Force
$key | New-ItemProperty -Name 'HostName' -Value 'example.com' -Force
$key | New-ItemProperty -Name 'UserName' -Value 'username' -Force
另请参阅https://winscp.net/eng/docs/custom_distribution#preconfigured_site