Created
June 28, 2021 19:59
-
-
Save joerodgers/fcc9568fa00647b1f383089279ae411e to your computer and use it in GitHub Desktop.
Example of how to download a file using Posh-SSH via SSH/SFTP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#requires -Modules Posh-SSH | |
$hostname = "server.contoso.com" | |
$keyFile = "C:\_temp\ssh-key.pem" | |
$userName = "johndoe" | |
$certPassword = ConvertTo-SecureString -String 'password' -AsPlainText -Force | |
$localPath = "c:\_temp\file.dat" | |
$remotePath = "/folder1/folder2/folder3" | |
$remoteFile = "file.dat" | |
New-SFTPSession ` | |
-ComputerName $hostname ` | |
-KeyFile $keyFile ` | |
-Credential ([PSCredential]::new($userName, $certPassword)) ` | |
-AcceptKey | |
Set-SFTPLocation ` | |
-SessionId 0 ` | |
-Path $remotePath | |
Get-SFTPFile ` | |
-SessionId 0 ` | |
-RemoteFile $remoteFile ` | |
-LocalPath $localPath ` | |
-Overwrite | |
Remove-SFTPSession ` | |
-SessionId 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment