Closed fullenw1 closed 2 weeks ago
I confirm, we face the same issue on Linux (Ubuntu 20.04 LTS)
FileLoadException: Could not load file or assembly 'Microsoft.Bcl.AsyncInterfaces, Version=8.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'.
Tested with
When you look at the $error what does the loadexception says? Sent from my iPhoneOn Jan 4, 2024, at 6:12 AM, DuyHai DOAN @.***> wrote: I confirm, we face the same issue
FileLoadException: Could not load file or assembly 'Microsoft.Bcl.AsyncInterfaces, Version=8.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'.
Tested with
Posh-SSH v 3.1.1 Posh-SSH v 3.1.2 Powershell Core 7.4.0 Powershell Core 7.5.0
—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you are subscribed to this thread.Message ID: @.***>
When you look at the $error what does the loadexception says? Sent from my iPhoneOn Jan 4, 2024, at 6:12 AM, DuyHai DOAN @.> wrote: I confirm, we face the same issue FileLoadException: Could not load file or assembly 'Microsoft.Bcl.AsyncInterfaces, Version=8.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. Tested with Posh-SSH v 3.1.1 Posh-SSH v 3.1.2 Powershell Core 7.4.0 Powershell Core 7.5.0 —Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you are subscribed to this thread.Message ID: @.>
Here is my test code
Write-Host "*** Installing Posh SSH Module 3.1.2 ***"
Install-Module -Name Posh-SSH -Force -RequiredVersion 3.1.2
Write-Host "*** Import Posh SSH Module ***"
try {
Import-Module Posh-SSH
} catch {
Write-Host "error = $($Error | Out-String)"
}
And here is the display
Installing Posh SSH Module 3.1.2 Import Posh SSH Module error = Import-Module: /home/docker/actions-runner/_work/_temp/55116c9b-0848-4837-ba77-fa8c3aa0f3ee.ps1:17 Line | 17 | Import-Module Posh-SSH |
~~~~~~ | Could not load file or assembly 'Microsoft.Bcl.AsyncInterfaces, | Version=8.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'.
I unlisted the module. It seems the last SSH.Net update added a dependency, so I can make it only work with one or the other at the moment. https://github.com/sshnet/SSH.NET/issues/1287
(I know nothing about powershell modules) Is it possible to package Microsoft.Bcl.AsyncInterfaces.dll alongside Renci.SshNet.dll?
I unlisted the module. It seems the last SSH.Net update added a dependency, so I can make it only work with one or the other at the moment. sshnet/SSH.NET#1287
Will you do a new release for the fix ?
Regards
I did and I get error’s depending on the version of .net used still trying to figure what broken with this latest nugget Sent from my iPhoneOn Jan 4, 2024, at 8:01 AM, Rob Hague @.***> wrote: (I know nothing about powershell modules) Is it possible to package Microsoft.Bcl.AsyncInterfaces.dll alongside Renci.SshNet.dll?
—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you commented.Message ID: @.***>
I unlisted the module. It seems the last SSH.Net update added a dependency, so I can make it only work with one or the other at the moment. sshnet/SSH.NET#1287
Will you do a new release for the fix ?
Regards
If I can fix it, seems the dependency messes stuff up when running under .ner standard 2.0
╭─ pwsh ~\Documents\GitHub\Posh-SSH\Source\PoshSSH\PoshSSH.Core\bin\Release\netstandard2.0 master ?9 ~1 09:51:58
╰─❯ New-SSHSession v0.local pi
PowerShell credential request
Enter your credentials.
Password for user pi: ********
New-SSHSession: Could not load file or assembly 'Microsoft.Bcl.AsyncInterfaces, Version=8.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. Could not find or load a specific file. (0x80131621)
╭─ pwsh ~\Documents\GitHub\Posh-SSH\Source\PoshSSH\PoshSSH.Core\bin\Release\netstandard2.0 master ?9 ~1 09:53:15
╰─❯ ls
Directory: C:\Users\Carlos Perez\Documents\GitHub\Posh-SSH\Source\PoshSSH\PoshSSH.Core\bin\Release\netstandard2.0
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a--- 10/31/2023 11:00 AM 26784 Microsoft.Bcl.AsyncInterfaces.dll
-a--- 1/4/2024 9:44 AM 5439 PoshSSH.deps.json
-a--- 1/4/2024 9:44 AM 46080 PoshSSH.dll
-a--- 1/4/2024 9:44 AM 22320 PoshSSH.pdb
╭─ pwsh ~\Documents\GitHub\Posh-SSH\Source\PoshSSH\PoshSSH.Core\bin\Release\netstandard2.0 master ?9 ~1 09:53:19
╰─❯ add-type -Path .\microsoft.Bcl.AsyncInterfaces.dll
Add-Type: Could not load file or assembly 'Microsoft.Bcl.AsyncInterfaces, Version=8.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'.
I copied the files straight from the .Netstandard 2.0 nugget for the library it will not even let me load it by hand
Where is Renci.SshNet.dll and SshNet.Security.Cryptography.dll? Should Microsoft.Bcl.AsyncInterfaces.dll be alongside those?
all of the files from the dependecies json file
─ pwsh ~\Documents\GitHub\Posh-SSH\Posh-SSH master ?9 ~1 10:10:09
╰─❯ ls
Directory: C:\Users\Carlos Perez\Documents\GitHub\Posh-SSH\Posh-SSH
Mode LastWriteTime Length Name
---- ------------- ------ ----
d---- 1/4/2024 9:35 AM Assembly
d---- 10/22/2023 1:56 PM en-US
d---- 6/2/2021 5:35 PM Format
-a--- 10/31/2023 11:00 AM 26784 Microsoft.Bcl.AsyncInterfaces.dll
-a--- 3/17/2021 8:03 PM 701992 Newtonsoft.Json.dll
-a--- 1/4/2024 9:37 AM 5342 Posh-SSH.psd1
-a--- 10/23/2023 7:40 AM 93572 Posh-SSH.psm1
-a--- 12/31/2023 9:37 AM 46080 PoshSSH.dll
-a--- 12/29/2023 9:57 AM 839168 Renci.SshNet.dll
-a--- 10/22/2017 8:53 PM 34816 SshNet.Security.Cryptography.dll
-a--- 1/25/2021 2:43 PM 20856 System.Buffers.dll
-a--- 12/2/2020 4:59 AM 1608160 System.Management.Automation.dll
-a--- 1/25/2021 2:43 PM 141184 System.Memory.dll
-a--- 1/25/2021 2:43 PM 115856 System.Numerics.Vectors.dll
-a--- 2/19/2020 6:05 AM 25984 System.Threading.Tasks.Extensions.dll
╭─ pwsh ~\Documents\GitHub\Posh-SSH\Posh-SSH master ?9 ~1 10:10:11
╰─❯ add-type -Path .\microsoft.Bcl.AsyncInterfaces.dll
Add-Type: Could not load file or assembly 'Microsoft.Bcl.AsyncInterfaces, Version=8.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'.
╭─ pwsh ~\Documents\GitHub\Posh-SSH\Posh-SSH master ?9 ~1 10:10:21
╰─❯
the .net standard 2.0 files load no problems under PS version 5.1
PS C:\Users\Carlos Perez> cd "C:\Users\Carlos Perez\Documents\GitHub\Posh-SSH\Posh-SSH"
PS C:\Users\Carlos Perez\Documents\GitHub\Posh-SSH\Posh-SSH> add-type -Path .\microsoft.Bcl.AsyncInterfaces.dll
PS C:\Users\Carlos Perez\Documents\GitHub\Posh-SSH\Posh-SSH>
Any more error details from $error.Exception
?
$error[0].exception | fl *
Message : Could not load file or assembly 'Microsoft.Bcl.AsyncInterfaces, Version=8.0.0.0, Culture=neutral,
PublicKeyToken=cc7b13ffcd2ddd51'.
FileName :
FusionLog :
TargetSite : System.Reflection.Assembly LoadFromAssemblyPath(System.String)
Data : {}
InnerException :
HelpLink :
Source : System.Private.CoreLib
HResult : -2146232799
StackTrace : at System.Runtime.Loader.AssemblyLoadContext.LoadFromAssemblyPath(String assemblyPath)
at System.Reflection.Assembly.LoadFrom(String assemblyFile)
at Microsoft.PowerShell.Commands.AddTypeCommand.LoadAssemblies(IEnumerable`1 assemblies)
at System.Management.Automation.CommandProcessorBase.Complete()
The HResult is 0x80131621 which has a few results on google, including https://github.com/pnp/powershell/discussions/1814
Perhaps there is some conflict somewhere. Does this show anything?
[System.AppDomain]::CurrentDomain.GetAssemblies() | Where-Object {$_.FullName -match "Microsoft.Bcl.AsyncInterfaces"} | Select-Object -Property FullName, Location | fl
Tried it at startup, after loading SSH.NET, after importing the module. Seems to error when it is actually used. DLL is in the same directory
╭─ pwsh ~\Documents\GitHub\Posh-SSH\Posh-SSH master ?9 ~1 10:10:21
╰─❯ [System.AppDomain]::CurrentDomain.GetAssemblies() | Where-Object {$_.FullName -match "Microsoft.Bcl.AsyncInterfaces"} | Select-Object -Property
FullName, Location | fl
╭─ pwsh ~\Documents\GitHub\Posh-SSH\Posh-SSH master ?9 ~1 11:14:26
╰─❯ Add-Type -Path .\Renci.SshNet.dll
╭─ pwsh ~\Documents\GitHub\Posh-SSH\Posh-SSH master ?9 ~1 11:15:01
╰─❯ [System.AppDomain]::CurrentDomain.GetAssemblies() | Where-Object {$_.FullName -match "Microsoft.Bcl.AsyncInterfaces"} | Select-Object -Property
FullName, Location | fl
╭─ pwsh ~\Documents\GitHub\Posh-SSH\Posh-SSH master ?9 ~1 11:15:03
╰─❯ import-module -verbose .\PoshSSH.dll
VERBOSE: Importing cmdlet 'Get-SSHHostKey'.
VERBOSE: Importing cmdlet 'Get-SCPItem'.
VERBOSE: Importing cmdlet 'Get-SFTPItem'.
VERBOSE: Importing cmdlet 'New-SFTPSession'.
VERBOSE: Importing cmdlet 'New-SSHSession'.
VERBOSE: Importing cmdlet 'Set-SCPItem'.
VERBOSE: Importing cmdlet 'Set-SFTPItem'.
VERBOSE: Importing cmdlet 'New-SSHMemoryKnownHost'.
VERBOSE: Importing cmdlet 'Get-SSHJsonKnownHost'.
VERBOSE: Importing cmdlet 'Get-SSHOpenSSHKnownHost'.
VERBOSE: Importing alias 'Get-SSHJsonKnowHost'.
╭─ pwsh ~\Documents\GitHub\Posh-SSH\Posh-SSH master ?9 ~1 11:15:31
╰─❯ New-SSHSession v0.local pi
PowerShell credential request
Enter your credentials.
Password for user pi: ********
New-SSHSession: Could not load file or assembly 'Microsoft.Bcl.AsyncInterfaces, Version=8.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. Could not find or load a specific file. (0x80131621)
╭─ pwsh ~\Documents\GitHub\Posh-SSH\Posh-SSH master ?9 ~1 11:15:41
╰─❯ [System.AppDomain]::CurrentDomain.GetAssemblies() | Where-Object {$_.FullName -match "Microsoft.Bcl.AsyncInterfaces"} | Select-Object -Property
FullName, Location | fl
╭─ pwsh ~\Documents\GitHub\Posh-SSH\Posh-SSH master ?9 ~1
I set on the project
Now I'm completely lost. I can load it by hand, it is in the CAG but it can not find it .. .
New-SSHSession: Could not load file or assembly 'Microsoft.Bcl.AsyncInterfaces, Version=8.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. Could not find or load a specific file. (0x80131621)
╭─ pwsh ~\Documents\GitHub\Posh-SSH\Posh-SSH master ?9 ~2 14:44:30
╰─❯ [Reflection.Assembly]::LoadFile('C:\Users\Carlos Perez\Documents\GitHub\Posh-SSH\Posh-SSH\Microsoft.Bcl.AsyncInterfaces.dll')
GAC Version Location
--- ------- --------
False v4.0.30319 C:\Users\Carlos Perez\Documents\GitHub\Posh-SSH\Posh-SSH\Microsoft.Bcl.AsyncInterfaces.dll
╭─ pwsh ~\Documents\GitHub\Posh-SSH\Posh-SSH master ?9 ~2 14:44:46
╰─❯ New-SSHSession v0.local pi
PowerShell credential request
Enter your credentials.
Password for user pi: ********
New-SSHSession: Could not load file or assembly 'Microsoft.Bcl.AsyncInterfaces, Version=8.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. Could not find or load a specific file. (0x80131621)
I have a C:\Program Files\PowerShell\7\Microsoft.Bcl.AsyncInterfaces.dll which is version 5.0.0.0
The problem could be that the SSH.NET nuspec defines an exact dependency (with square brackets) on 8.0.0 and because PS7 has a dependency on a different version already, it refuses to load another.
You could try the following diff in SSH.NET:
diff --git a/src/Renci.SshNet/Renci.SshNet.csproj b/src/Renci.SshNet/Renci.SshNet.csproj
index 877b3b89..334df508 100644
--- a/src/Renci.SshNet/Renci.SshNet.csproj
+++ b/src/Renci.SshNet/Renci.SshNet.csproj
@@ -14,7 +14,7 @@
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'net462' or '$(TargetFramework)' == 'netstandard2.0' ">
- <PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="8.0.0" />
+ <PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="1.0.0" /> <!-- or a higher version -->
</ItemGroup>
<PropertyGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' or '$(TargetFramework)' == 'netstandard2.1' or '$(TargetFramework)' == 'net6.0' or '$(TargetFramework)' == 'net7.0' or '$(TargetFramework)' == 'net8.0' ">
and try again with a local build of the library.
If things are still not getting anywhere, I would be in favour of removing the dependency from the library to unblock your module. It is not a necessary part of the library. cc @wojciechnagorski
@Rob-Hague Thanks!! it worked now on both versions of PS, I will do more tests before I update my module
Great
It would be useful if you could do a quick check with a local build using version 8.0.0 and see whether it still works (which would imply the problem would be fixed by https://github.com/sshnet/SSH.NET/pull/1288), or if it only works with a version <= 5.0.0 or whatever PS7 seems to be using (in which case, we should probably remove the dependency altogether)
@darkoperator @Rob-Hague I'm confused. If the csproj diff fixes it, wouldn't this mean the problem is version 8.0.0? In this case https://github.com/sshnet/SSH.NET/pull/1288 wouldn't fix it, since SSH.NET would still need 8.0.0 (it would just also accept 9.0 etc.).
If PowerShell can't handle the newer Microsoft.Bcl.AsyncInterfaces Version for whatever reason, it would probably be best for SSH.NET to require >=1.0.0 instead >=8.0.0 . I doubt that SSH.NET actually needs an up-to-date version since it's just a compat package for .NET Framework / .NET Standard.
yep, with version 1.1.0 it worked in terms of loading and establishing a SSH connection. Version 8.0.0 loading was the version causing the problem in PS 7
Can you prepare a PR?
I think this one is covering it https://github.com/sshnet/SSH.NET/pull/1288
@mus65 I'm not so clear on the nuances of dll loading 🙂
Can you can modify your PR to take version >= 1.0.0?
@WojciechNagorski @Rob-Hague @darkoperator I updated my PR to fix both issues: https://github.com/sshnet/SSH.NET/pull/1288
@darkoperator PowerShell distributes Microsoft.Bcl.AsyncInterfaces, so if you want to load another version, that creates a conflict. Every time the PowerShell team changes the version of this assembly, it will break your module.
The technical explanation is here: https://learn.microsoft.com/en-us/powershell/scripting/dev-cross-plat/resolving-dependency-conflicts?view=powershell-7.4
In the quick version (this is contained in the previous document), if you define a class that implements IModuleAssemblyInitializer , when the module loads, you can insert code that allows you to load a library with the version of your choice (via an AssemblyLoadContext)
I'm giving you the repository of the person who worked on the subject at the time (same use case as the doc) https://github.com/rjmholt/ModuleDependencyIsolationExample/tree/master
A random example : https://github.com/PSBicep/BicepNet/blob/main/BicepNet.PS/LoadContext/ModuleInitializer.cs
Hello @darkoperator
Any update on the fix ? Should I use the latest release of the module ?
You can use the latest available in the gallery, at the moment waiting to see when they will push a new nugget with the fixed version. If in a couple of weeks they do not push one I will push my own version by compiling from the development branch.
@doanduyhai can you give the pre-release a test https://github.com/darkoperator/Posh-SSH/releases/tag/3.1.3-Beta1
Hello @darkoperator
I'll be happy to test the Beta release
However, because I'm a newbie in Powershell and .Net environment, I don't know how to use your beta package in .zip release form
Usually, to install a Powershell module, I just use the command Install-Module -Name Posh-SSH
Please give me instructions on how to deploy the zip file and I'll be happy to test it
Regards
@darkoperator
Here is what I get
Source code:
Write-Host "****** Loading Posh-SSH beta version ********"
Import-Module -Name /_redacted_/posh-ssh-binaries/Posh-SSH -Verbose
Result:
** Loading Posh-SSH beta version **** VERBOSE: Loading module from path '/_redacted_/posh-ssh-binaries/Posh-SSH/Posh-SSH.psd1'. VERBOSE: Loading 'FormatsToProcess' from path '/_redacted_/posh-ssh-binaries/Posh-SSH/Format/SSHSession.Format.ps1xml'. VERBOSE: Loading 'FormatsToProcess' from path '/_redacted_/posh-ssh-binaries/Posh-SSH/Format/SFTPSession.Format.ps1xml'. VERBOSE: Loading 'FormatsToProcess' from path '/_redacted_/posh-ssh-binaries/Posh-SSH/Format/Renci.SshNet.SshCommand.Format.ps1xml'. VERBOSE: Loading 'FormatsToProcess' from path '/_redacted_/posh-ssh-binaries/Posh-SSH/Format/Renci.SshNet.Sftp.SftpFile.Format.ps1xml'. VERBOSE: Loading module from path '/_redacted_/posh-ssh-binaries/Posh-SSH/PoshSSH.dll'. VERBOSE: Importing cmdlet 'Get-SSHHostKey'. VERBOSE: Importing cmdlet 'Get-SCPItem'. VERBOSE: Importing cmdlet 'Get-SFTPItem'. VERBOSE: Importing cmdlet 'New-SFTPSession'. VERBOSE: Importing cmdlet 'New-SSHSession'. VERBOSE: Importing cmdlet 'Set-SCPItem'. VERBOSE: Importing cmdlet 'Set-SFTPItem'. VERBOSE: Importing cmdlet 'New-SSHMemoryKnownHost'. VERBOSE: Importing cmdlet 'Get-SSHJsonKnownHost'. VERBOSE: Importing cmdlet 'Get-SSHOpenSSHKnownHost'. VERBOSE: Importing alias 'Get-SSHJsonKnowHost'. VERBOSE: Loading module from path '/home/docker4sg/actions-runner/_work/test_repo1/test_repo1/posh-ssh-binaries/Posh-SSH/Posh-SSH.psm1'. VERBOSE: Exporting function 'Get-SSHSession'. VERBOSE: Exporting function 'Remove-SSHSession'. VERBOSE: Exporting function 'Invoke-SSHCommand'. VERBOSE: Exporting function 'Get-PoshSSHModVersion'. VERBOSE: Exporting function 'Invoke-SSHCommandStream'. VERBOSE: Exporting function 'New-SSHShellStream'. VERBOSE: Exporting function 'Invoke-SSHStreamExpectAction'. VERBOSE: Exporting function 'Invoke-SSHStreamExpectSecureAction'. VERBOSE: Exporting function 'Invoke-SSHStreamShellCommand'. VERBOSE: Exporting function 'Get-SFTPSession'. VERBOSE: Exporting function 'Remove-SFTPSession'. VERBOSE: Exporting function 'Get-SFTPChildItem'. VERBOSE: Exporting function 'Test-SFTPPath'. VERBOSE: Exporting function 'Remove-SFTPItem'. VERBOSE: Exporting function 'Move-SFTPItem'. VERBOSE: Exporting function 'Set-SFTPLocation'. VERBOSE: Exporting function 'Get-SFTPLocation'. VERBOSE: Exporting function 'Rename-SFTPFile'. VERBOSE: Exporting function 'Get-SFTPPathAttribute'. VERBOSE: Exporting function 'Set-SFTPPathAttribute'. VERBOSE: Exporting function 'Get-SFTPPathInformation'. VERBOSE: Exporting function 'New-SFTPSymlink'. VERBOSE: Exporting function 'Get-SFTPContent'. VERBOSE: Exporting function 'Set-SFTPContent'. VERBOSE: Exporting function 'New-SFTPFileStream'. VERBOSE: Exporting function 'New-SFTPItem'. VERBOSE: Exporting function 'New-SSHLocalPortForward'. VERBOSE: Exporting function 'New-SSHRemotePortForward'. VERBOSE: Exporting function 'New-SSHDynamicPortForward'. VERBOSE: Exporting function 'Get-SSHPortForward'. VERBOSE: Exporting function 'Stop-SSHPortForward'. VERBOSE: Exporting function 'Start-SSHPortForward'. VERBOSE: Exporting function 'Get-SSHTrustedHost'. VERBOSE: Exporting function 'New-SSHTrustedHost'. VERBOSE: Exporting function 'Remove-SSHTrustedHost'. VERBOSE: Exporting function 'Get-SSHRegistryKnownHost'. VERBOSE: Exporting function 'Convert-SSHRegistryToJSonKnownHost'. VERBOSE: Exporting alias 'Get-SSHJsonKnowHost'. VERBOSE: Importing function 'Convert-SSHRegistryToJSonKnownHost'. VERBOSE: Importing function 'Get-PoshSSHModVersion'. VERBOSE: Importing function 'Get-SFTPChildItem'. VERBOSE: Importing function 'Get-SFTPContent'. VERBOSE: Importing function 'Get-SFTPLocation'. VERBOSE: Importing function 'Get-SFTPPathAttribute'. VERBOSE: Importing function 'Get-SFTPPathInformation'. VERBOSE: Importing function 'Get-SFTPSession'. VERBOSE: Importing function 'Get-SSHPortForward'. VERBOSE: Importing function 'Get-SSHRegistryKnownHost'. VERBOSE: Importing function 'Get-SSHSession'. VERBOSE: Importing function 'Get-SSHTrustedHost'. VERBOSE: Importing function 'Invoke-SSHCommand'. VERBOSE: Importing function 'Invoke-SSHCommandStream'. VERBOSE: Importing function 'Invoke-SSHStreamExpectAction'. VERBOSE: Importing function 'Invoke-SSHStreamExpectSecureAction'. VERBOSE: Importing function 'Invoke-SSHStreamShellCommand'. VERBOSE: Importing function 'Move-SFTPItem'. VERBOSE: Importing function 'New-SFTPFileStream'. VERBOSE: Importing function 'New-SFTPItem'. VERBOSE: Importing function 'New-SFTPSymlink'. VERBOSE: Importing function 'New-SSHDynamicPortForward'. VERBOSE: Importing function 'New-SSHLocalPortForward'. VERBOSE: Importing function 'New-SSHRemotePortForward'. VERBOSE: Importing function 'New-SSHShellStream'. VERBOSE: Importing function 'New-SSHTrustedHost'. VERBOSE: Importing function 'Remove-SFTPItem'. VERBOSE: Importing function 'Remove-SFTPSession'. VERBOSE: Importing function 'Remove-SSHSession'. VERBOSE: Importing function 'Remove-SSHTrustedHost'. VERBOSE: Importing function 'Rename-SFTPFile'. VERBOSE: Importing function 'Set-SFTPContent'. VERBOSE: Importing function 'Set-SFTPLocation'. VERBOSE: Importing function 'Set-SFTPPathAttribute'. VERBOSE: Importing function 'Start-SSHPortForward'. VERBOSE: Importing function 'Stop-SSHPortForward'. VERBOSE: Importing function 'Test-SFTPPath'. VERBOSE: Importing alias 'Get-SSHJsonKnowHost'. VERBOSE: Exporting function 'Convert-SSHRegistryToJSonKnownHost'. VERBOSE: Exporting function 'Get-PoshSSHModVersion'. VERBOSE: Exporting function 'Get-SFTPChildItem'. VERBOSE: Exporting function 'Get-SFTPContent'. VERBOSE: Exporting function 'Get-SFTPLocation'. VERBOSE: Exporting function 'Get-SFTPPathAttribute'. VERBOSE: Exporting function 'Get-SFTPPathInformation'. VERBOSE: Exporting function 'Get-SFTPSession'. VERBOSE: Exporting function 'Get-SSHPortForward'. VERBOSE: Exporting function 'Get-SSHRegistryKnownHost'. VERBOSE: Exporting function 'Get-SSHSession'. VERBOSE: Exporting function 'Get-SSHTrustedHost'. VERBOSE: Exporting function 'Invoke-SSHCommand'. VERBOSE: Exporting function 'Invoke-SSHCommandStream'. VERBOSE: Exporting function 'Invoke-SSHStreamExpectAction'. VERBOSE: Exporting function 'Invoke-SSHStreamExpectSecureAction'. VERBOSE: Exporting function 'Invoke-SSHStreamShellCommand'. VERBOSE: Exporting function 'Move-SFTPItem'. VERBOSE: Exporting function 'New-SFTPFileStream'. VERBOSE: Exporting function 'New-SFTPItem'. VERBOSE: Exporting function 'New-SFTPSymlink'. VERBOSE: Exporting function 'New-SSHDynamicPortForward'. VERBOSE: Exporting function 'New-SSHLocalPortForward'. VERBOSE: Exporting function 'New-SSHRemotePortForward'. VERBOSE: Exporting function 'New-SSHShellStream'. VERBOSE: Exporting function 'New-SSHTrustedHost'. VERBOSE: Exporting function 'Remove-SFTPItem'. VERBOSE: Exporting function 'Remove-SFTPSession'. VERBOSE: Exporting function 'Remove-SSHSession'. VERBOSE: Exporting function 'Remove-SSHTrustedHost'. VERBOSE: Exporting function 'Rename-SFTPFile'. VERBOSE: Exporting function 'Set-SFTPContent'. VERBOSE: Exporting function 'Set-SFTPLocation'. VERBOSE: Exporting function 'Set-SFTPPathAttribute'. VERBOSE: Exporting function 'Start-SSHPortForward'. VERBOSE: Exporting function 'Stop-SSHPortForward'. VERBOSE: Exporting function 'Test-SFTPPath'. VERBOSE: Exporting cmdlet 'Get-SSHHostKey'. VERBOSE: Exporting cmdlet 'Get-SCPItem'. VERBOSE: Exporting cmdlet 'Get-SFTPItem'. VERBOSE: Exporting cmdlet 'New-SFTPSession'. VERBOSE: Exporting cmdlet 'New-SSHSession'. VERBOSE: Exporting cmdlet 'Set-SCPItem'. VERBOSE: Exporting cmdlet 'Set-SFTPItem'. VERBOSE: Exporting cmdlet 'New-SSHMemoryKnownHost'. VERBOSE: Exporting cmdlet 'Get-SSHJsonKnownHost'. VERBOSE: Exporting cmdlet 'Get-SSHOpenSSHKnownHost'. VERBOSE: Exporting alias 'Get-SSHJsonKnowHost'. VERBOSE: Importing cmdlet 'Get-SCPItem'. VERBOSE: Importing cmdlet 'Get-SFTPItem'. VERBOSE: Importing cmdlet 'Get-SSHHostKey'. VERBOSE: Importing cmdlet 'Get-SSHJsonKnownHost'. VERBOSE: Importing cmdlet 'Get-SSHOpenSSHKnownHost'. VERBOSE: Importing cmdlet 'New-SFTPSession'. VERBOSE: Importing cmdlet 'New-SSHMemoryKnownHost'. VERBOSE: Importing cmdlet 'New-SSHSession'. VERBOSE: Importing cmdlet 'Set-SCPItem'. VERBOSE: Importing cmdlet 'Set-SFTPItem'. VERBOSE: Importing function 'Convert-SSHRegistryToJSonKnownHost'. VERBOSE: Importing function 'Get-PoshSSHModVersion'. VERBOSE: Importing function 'Get-SFTPChildItem'. VERBOSE: Importing function 'Get-SFTPContent'. VERBOSE: Importing function 'Get-SFTPLocation'. VERBOSE: Importing function 'Get-SFTPPathAttribute'. VERBOSE: Importing function 'Get-SFTPPathInformation'. VERBOSE: Importing function 'Get-SFTPSession'. VERBOSE: Importing function 'Get-SSHPortForward'. VERBOSE: Importing function 'Get-SSHRegistryKnownHost'. VERBOSE: Importing function 'Get-SSHSession'. VERBOSE: Importing function 'Get-SSHTrustedHost'. VERBOSE: Importing function 'Invoke-SSHCommand'. VERBOSE: Importing function 'Invoke-SSHCommandStream'. VERBOSE: Importing function 'Invoke-SSHStreamExpectAction'. VERBOSE: Importing function 'Invoke-SSHStreamExpectSecureAction'. VERBOSE: Importing function 'Invoke-SSHStreamShellCommand'. VERBOSE: Importing function 'Move-SFTPItem'. VERBOSE: Importing function 'New-SFTPFileStream'. VERBOSE: Importing function 'New-SFTPItem'. VERBOSE: Importing function 'New-SFTPSymlink'. VERBOSE: Importing function 'New-SSHDynamicPortForward'. VERBOSE: Importing function 'New-SSHLocalPortForward'. VERBOSE: Importing function 'New-SSHRemotePortForward'. VERBOSE: Importing function 'New-SSHShellStream'. VERBOSE: Importing function 'New-SSHTrustedHost'. VERBOSE: Importing function 'Remove-SFTPItem'. VERBOSE: Importing function 'Remove-SFTPSession'. VERBOSE: Importing function 'Remove-SSHSession'. VERBOSE: Importing function 'Remove-SSHTrustedHost'. VERBOSE: Importing function 'Rename-SFTPFile'. VERBOSE: Importing function 'Set-SFTPContent'. VERBOSE: Importing function 'Set-SFTPLocation'. VERBOSE: Importing function 'Set-SFTPPathAttribute'. VERBOSE: Importing function 'Start-SSHPortForward'. VERBOSE: Importing function 'Stop-SSHPortForward'. VERBOSE: Importing function 'Test-SFTPPath'. VERBOSE: Importing alias 'Get-SSHJsonKnowHost'.
Integration test with a real SFTP endpoint
Source:
Write-Host "Downloading secret 'private-ssh-key' from KeyVault '__redacted__' to local private.pem file"
az keyvault secret download `
--vault-name "__redacted__" `
--name "sftp-private-ssh-key" `
--file ./private.pem `
--encoding ascii
$username="__redacted__"
$password = ""
$secureStringPwd = $password | ConvertTo-SecureString -AsPlainText -Force
$credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $username, $secureStringPwd
try {
$blobEndpoint = "__redacted__"
Write-Host "Connecting to SFTP endpoint '$blobEndpoint' with user '$username'"
$currentSession=New-SFTPSession `
-Computername "$blobEndpoint" `
-Credential $credential `
-KeyFile ./private.pem `
-AcceptKey `
-Force
} finally {
if($currentSession -ne $null) {
Write-Host "Disconnecting SFTP session from host '$blobEndpoint'"
Remove-SFTPSession $currentSession
}
if (Test-Path "./private.pem") {
Write-Host "Removing local 'private.pem' file"
Remove-Item "./private.pem"
}
}
Result:
Downloading secret 'private-ssh-key' from KeyVault '_redacted_' to local private.pem file Connecting to SFTP endpoint '_redacted_' with user '_redacted_' WARNING: Host key is not being verified since Force switch is used. Disconnecting SFTP session from host '_redacted_' Removing local 'private.pem' file
Thanks, was this by any chance against a Cisco device?
Thanks, was this by any chance against a Cisco device?
No, I was testing against an Azure Storage Account with SFTP feature enabled
I was experiencing this issue in an Azure Function running Powershell 7. Setting the required version of this module to the new beta release resolved the issue.
Is this fixed in version Posh-SSH 3.1.3
? That's the current version in the PowerShell gallery but that version is marked here on GitHub as being Beta
.
Yes, need to pusblish the zipSent from my iPhoneOn Jan 30, 2024, at 10:16 AM, DarkLite1 @.***> wrote: Is this fixed in version Posh-SSH 3.1.3? That's the current version in the PowerShell gallery but that version is marked here on GitHub as being Beta.
—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you were mentioned.Message ID: @.***>
I have this error only on PowerShell Core and not on Windows PowerShell 5.1 It was working fine until the latest release...
Here is my PowerShell configuration: