Note that you have to specify the local file name. The public key has to be stored on the host in the authorized_keys file in the user’s. On a Linux machine, you would generate the corresponding key pair with ssh-keygen -t rsa. I will demonstrate this with the Get-SCPFile cmdlet that allows you to download files via the SCP protocol: Get-SCPFile -ComputerName "mySSHserver" -Credential $Credentials -Key "myPrivateKeyFile"-RemoteFile "/path/file" -LocalFile "C:\path\file" Posh-SSH also supports public key authentication. In this case, you don’t have to create an SFTP session first: $Credentials = Get-Credential To download an entire folder with its subfolders, you need the Get-SCPFolder cmdlet. You first have to create a PSCredential object with Get-Credential. Unlike Invoke-WebRequest, you can’t just pass the user name with the -Credential parameter. Get-SFTPFile -SFTPSession $Session -RemoteFile "/path/file" -LocalPath "C:\path\" $Session = New-SFTPSession -ComputerName "mySFTPserver" -Credential $Credentials To do so, you first have to establish an SFTP session with the module’s New-SFTPSession cmdlet: $Credentials = Get-Credential The Get-SFTPFile cmdlet allows you to download via SFTP.
0 Comments
Leave a Reply. |