Receive-WinSCPItem


Synopsis

Receives objects from an active WinSCP Session.


Syntax

Receive-WinSCPItem [-WinSCPSession] <Session> [-Path] <String[]> [[-Destination] <String>] [-Remove] [[-TransferOptions] <TransferOptions>] [<CommonParameters>]

Description

After creating a valid WinSCP Session, this function can be used to receive objects and remove them from the remote source if desired.


Parameters

WinSCPSession <WinSCP.Session>

A valid open WinSCP Session, returned from New-WinSCPSession.

  • Required: True
  • Position: 0
  • Default Value:
  • Accept Pipeline Input: True (ByValue)
  • Accept Wildcard Characters: False

Path <String[]>

Full path to remote directory followed by slash and wildcard to select files or subdirectories to download. When wildcard is omitted (path ends with slash), all files and subdirectories in the remote directory are downloaded.

  • Required: True
  • Position: 1
  • Default Value:
  • Accept Pipeline Input: True (ByPropertyName)
  • Accept Wildcard Characters: True

Destination <String>

Full path to download the file to. When downloading multiple files, the filename in the path should be replaced with operation mask or omitted (path ends with slash).

  • Required: False
  • Position: 2
  • Default Value: $pwd (Primary Working Directory)
  • Accept Pipeline Input: False
  • Accept Wildcard Characters: False

Remove <SwitchParameter>

When present, deletes source file(s) after transfer.

  • Required: False
  • Position: Named
  • Default Value:
  • Accept Pipeline Input: False
  • Accept Wildcard Characters: False

TransferOptions <WinSCP.TransferOptions>

Defines options for file transfers.

  • Required: False
  • Position: 3
  • Default Value: New-Object -TypeName WinSCP.TransferOptions
  • Accept Pipeline Input: False
  • Accept Wildcard Characters: False

CommonParameters <CommonParameters>

This cmdlet supports the common parameters: Verbose, Debug, ErrorAction, ErrorVariable, WarningAction, WarningVariable, OutBuffer, PipelineVariable, and OutVariable.


Inputs

WinSCP.Session

  • Represents a session and provides methods for manipulating remote files over SFTP, SCP or FTP session.

System.String

  • Represents text as a series of Unicode characters.

Outputs

WinSCP.TransferOperationResult

  • Represents results of transfer operation.

Notes

If the WinSCPSession is piped into this command, the connection will be closed and the object will be disposed upon completion of the command.


Example 1

PS C:\> New-WinSCPSession -Credential (New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $env:USERNAME, (New-Object -TypeName System.Security.SecureString)) -HostName $env:COMPUTERNAME -Protocol Ftp | Receive-WinSCPItem -Path '/rDir/rFile.txt' -Destination 'C:\lDir\lFile.txt'

Transfers         Failures IsSuccess
---------         -------- ---------
{/rDir/rFile.txt} {}       True

Example 2

PS C:\> $credential = Get-Credential
PS C:\> $session = New-WinSCPSession -Credential $credential -Hostname 'myftphost.org' -SshHostKeyFingerprint 'ssh-rsa 1024 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx'
PS C:\> Receive-WinSCPItem -WinSCPSession $session -Path '/rDir/rFile.txt' -Destination 'C:\lDir\lFile.txt' -Remove

Transfers         Failures IsSuccess
---------         -------- ---------
{/rDir/rFile.txt} {}       True

Fork me on GitHub