【问题标题】:Save a session in WinSCP through PowerShell通过 PowerShell 在 WinSCP 中保存会话
【发布时间】:2020-03-19 10:03:21
【问题描述】:

我想在 WinSCP 中通过 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
}   

请帮助我,在此先感谢:)

【问题讨论】:

    标签: windows powershell winscp


    【解决方案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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-05-18
      • 2011-10-18
      • 2019-06-15
      • 1970-01-01
      • 2020-02-25
      • 2021-12-02
      • 2016-12-25
      相关资源
      最近更新 更多