Posh-SSH Cmdlet 无法识别 SFTP 上传到 PowerShell 中的 Azure Blob 容器

问题描述 投票:0回答:1

我正在尝试在 Windows 10 上使用 SFTP 和 PowerShell 将文件从本地目录上传到 Azure Blob 容器。我决定使用 Posh-SSH 模块来完成此任务。但是,我遇到了 PowerShell 无法识别 Posh-SSH cmdlet(Set-SFTPFile、Get-SFTPFile)的问题。这是我迄今为止尝试过的:

  1. 使用 Install-Module -Name Posh-SSH -Scope CurrentUser -Force 安装了 Posh-SSH。
  2. 使用 Import-Module Posh-SSH 将 Posh-SSH 导入到我的会话中。
  3. 尝试使用 Set-SFTPFile cmdlet 通过 SFTP 将文件上传到我的 Azure Blob 容器: 电源外壳 代码: $SFTPSession = New-SFTPSession -ComputerName "" -Credential (Get-Credential) -AcceptKey Set-SFTPFile -SessionId $SFTPSession.SessionId -LocalFile "文件路径" -RemotePath "/container1"

但是,我收到一条错误,表明术语“Set-SFTPFile”未被识别为 cmdlet、函数、脚本文件或可操作程序的名称。

我通过检查Get-Module -ListAvailable Posh-SSH确认Posh-SSH已安装,这表明该模块已安装。

  1. 为什么 Posh-SSH cmdlet 在我的 PowerShell 会话中无法识别?
  2. 是否有正确导入或使用 Posh-SSH cmdlet 进行 SFTP 文件传输的特定方法?
  3. Posh-SSH 通过 SFTP 将文件上传到 Azure Blob 容器是否需要任何其他步骤或配置? 如果您能提供有关如何解决这些问题或通过 SFTP 将文件上传到 Azure Blob 存储的替代方法的指导,我们将不胜感激。 环境:

Windows 11 PowerShell版本:5.1也在7中尝试过 Posh-SSH 版本:3.1.3

azure powershell posh-ssh
1个回答
0
投票

在 PowerShell 中无法识别用于 SFTP 上传到 Azure Blob 容器的 Posh-SSH Cmdlet。

Get-SFTPFile
cmd 已替换为
get-sftpitem

您可以尝试使用

Get-SFTPFile
Get-SFTPItem
,而不是使用
Set-SFTPItem
cmdlet。

Install-Module -Name Posh-SSH -Scope CurrentUser -Force
Import-Module Posh-SSH
$password = ConvertTo-SecureString “password” -AsPlainText -Force
$creds = New-Object System.Management.Automation.PSCredential (“user1”, $password)
$Test = New-SFTPSession -ComputerName " 10.80.1.81" -Credential $Credential -Verbose:($PSBoundParameters["Verbose"] -eq $true) -ErrorAction "Stop"
New-SFTPItem -SFTPSession $Test -Path "Path to file" -ItemType "File"
Set-SFTPItem -SFTPSession $Test -Destination "somedestination" -Path "somefile" -Force -Verbose:($PSBoundParameters["Verbose"] -eq $true) -ErrorAction "Stop"

回复:

enter image description here

参考'Get-SFTPFile'在v3.0中不存在

Set-SFTPFile:未将对象引用设置到对象的实例

© www.soinside.com 2019 - 2024. All rights reserved.