Differences

This shows you the differences between the selected revisions of the page.

2014-09-23 2014-09-23
Updated example to reflect changes to the powershell module. (107.5.184.201) Updated examples (107.5.184.201)
Line 84: Line 84:
<code powershell> <code powershell>
-$session = New-WinSCPSessionOptions -Hostname myftphost.org -Username ftpuser -password "FtpUserPword" -SshHostKeyFingerprint "ssh-rsa 1024 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx" | Open-WinSCPSession +# Define the options for the WinSCP Session. 
-Receive-WinSCPItem -WinSCPSession $session -RemoteItem "rDir/rFile.txt" -LocalItem "C:\lDir\lFile.txt" -RemoveRemoteItem+$options = New-WinSCPSessionOptions -Hostname myftphost.org -Username user -password "Pword" -SshHostKeyFingerprint "ssh-rsa 1024 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx" 
 +# Open the WinSCP Session with the defined options. 
 +$session = Open-WinSCPSession -SessionOptions $options 
 +# Using the open WinSCPSession, download the file from the remote host to the local host. 
 +Receive-WinSCPItem -WinSCPSession $session -RemoteItem "./rDir/rFile.txt" -LocalItem "C:\lDir\lFile.txt" 
 +# Close the WinSCPSession after completion.
Close-WinSCPSession -WinSCPSession $session Close-WinSCPSession -WinSCPSession $session
 +
 +# Accomplish the same task with one line of code.
 +# Piping the WinSCPSession into the Receive-WinSCPItem auto disposes the object after completion.
 +Open-WinSCPSession -SessionOptions (New-WinSCPSessionOptions -Hostname myftphost.org -Username user -password "Pword" -SshHostKeyFingerprint "ssh-rsa 1024 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx") |
 +    Receive-WinSCPItem -RemoteItem "./rDir/rFile.txt" -LocalItem "C:\lDir\lFile.txt"
</code> </code>

Last modified: by 107.5.184.201