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

This topic contains 1 reply, has 2 voices, and was last updated by Profile photo of Don Jones Don Jones 8 months ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #34347
    Profile photo of Derek Russ
    Derek Russ
    Participant

    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
    
    
    
    #34349
    Profile photo of Don Jones
    Don Jones
    Keymaster

    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.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.