Using Posh-SSH to retrieve contents in a directory using SFTP

Hello,

I have grabbed the following code off of the posh-ssh site that i am trying to use to connect to an SFTP site and download the contents of a folder. it is prompting me for the site name and such. why is it not grabbing the information from $sftpsession?

Thanks,

Derek

$sftpUser = “sftpuser”
$sftpPass = ConvertTo-SecureString -String “password” -AsPlainText -Force
 $sftpCred = new-object -typename System.Management.Automation.PSCredential -argumentlist $sftpUser, $sftpPass
 $sftpSession = New-SFTPSession -ComputerName sftp.site.com -Credential $sftpCred -Port 2000

Get-SCPFolder   -LocalFolder "C:\folder\" -remotefolder "/folder/" 

$sftpSession.Disconnect()
 Get-SFTPFile : Object reference not set to an instance of an object

You might actually ask on that site, but at a guess, I don’t see you passing the session to the command. I’d imagine there’s a parameter for doing so.