Janet
Janet

Reputation: 33

Connect to SFTP using PowerShell and download files

I am aware that there is a similar question asked previously but the solutions primarily focus on using WinSCP. I'm fairly new to SFTP and PowerShell as well, and I need help downloading files from an SFTP server onto my application server.

I believe that the Posh-SSH module can help with establishing an SFTP connection, but most code I have seen until now involves uploading files onto the SFTP server, not downloading from... would appreciate any advice!

Upvotes: 2

Views: 11838

Answers (1)

Martin Prikryl
Martin Prikryl

Reputation: 202088

Just use Get-SFTPItem cmdlet (Get-SFTPFile in older versions):

$remotePath = "/remote/path/file.ext"
$localPath = "C:\local\path\file.ext"
Get-SFTPItem -SessionId $sessionId -Path $remotePath -Destination $localPath

WinSCP will work too though:
Download files from SFTP server using PowerShell

Upvotes: 1

Related Questions