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

This topic contains 1 reply, has 2 voices, and was last updated by  Don Jones 2 years, 4 months ago.

  • Author
  • #34347

    Derek Russ


    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?



    $sftpUser = “sftpuser”
    $sftpPass = ConvertTo-SecureString -String “password” -AsPlainText -Force
     $sftpCred = new-object -typename System.Management.Automation.PSCredential -argumentlist $sftpUser, $sftpPass
     $sftpSession = New-SFTPSession -ComputerName -Credential $sftpCred -Port 2000
    Get-SCPFolder   -LocalFolder "C:\folder\" -remotefolder "/folder/" 
     Get-SFTPFile : Object reference not set to an instance of an object
  • #34349

    Don Jones

    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.

You must be logged in to reply to this topic.