Differences
This shows you the differences between the selected revisions of the page.
2013-05-09 | 2013-05-15 | ||
5.2.1 Renamed WinSCP .NET assembly to winscpnet.dll to avoid conflicts with winscp.exe (martin) | library_powershell + new event handling syntax (martin) | ||
Line 223: | Line 223: | ||
==== [[powershell]] PowerShell Example ==== | ==== [[powershell]] PowerShell Example ==== | ||
+ | Learn more about [[library_powershell|using WinSCP .NET assembly from PowerShell]]. | ||
+ | |||
&beta (* .dll *) | &beta (* .dll *) | ||
<code powershell> | <code powershell> | ||
Line 233: | Line 235: | ||
function FileTransferred | function FileTransferred | ||
{ | { | ||
- | if ($_.Error -eq $Null) | + | Param($e) |
+ | |||
+ | ····if ($e.Error -eq $Null) | ||
{ | { | ||
- | Write-Host ("Upload of {0} succeeded" -f $_.FileName) | + | Write-Host ("Upload of {0} succeeded" -f $e.FileName) |
} | } | ||
else | else | ||
{ | { | ||
- | Write-Host ("Upload of {0} failed: {1}" -f $_.FileName, $_.Error) | + | Write-Host ("Upload of {0} failed: {1}" -f $e.FileName, $e.Error) |
} | } | ||
- | if ($_.Chmod -ne $Null) | + | if ($e.Chmod -ne $Null) |
{ | { | ||
- | if ($_.Chmod.Error -eq $Null) | + | if ($e.Chmod.Error -eq $Null) |
{ | { | ||
- | Write-Host ("Permisions of {0} set to {1}" -f $_.Chmod.FileName, $_.Chmod.FilePermissions) | + | Write-Host ("Permisions of {0} set to {1}" -f $e.Chmod.FileName, $e.Chmod.FilePermissions) |
} | } | ||
else | else | ||
{ | { | ||
- | Write-Host ("Setting permissions of {0} failed: {1}" -f $_.Chmod.FileName, $_.Chmod.Error) | + | Write-Host ("Setting permissions of {0} failed: {1}" -f $e.Chmod.FileName, $e.Chmod.Error) |
} | } | ||
Line 256: | Line 260: | ||
else | else | ||
{ | { | ||
- | Write-Host ("Permissions of {0} kept with their defaults" -f $_.Destination) | + | Write-Host ("Permissions of {0} kept with their defaults" -f $e.Destination) |
} | } | ||
- | if ($_.Touch -ne $Null) | + | if ($e.Touch -ne $Null) |
{ | { | ||
- | if ($_.Touch.Error -eq $Null) | + | if ($e.Touch.Error -eq $Null) |
{ | { | ||
- | Write-Host ("Timestamp of {0} set to {1}" -f $_.Touch.FileName, $_.Touch.LastWriteTime) | + | Write-Host ("Timestamp of {0} set to {1}" -f $e.Touch.FileName, $e.Touch.LastWriteTime) |
} | } | ||
else | else | ||
{ | { | ||
- | Write-Host ("Setting timestamp of {0} failed: {1}" -f $_.Touch.FileName, $_.Touch.Error) | + | Write-Host ("Setting timestamp of {0} failed: {1}" -f $e.Touch.FileName, $e.Touch.Error) |
} | } | ||
Line 274: | Line 278: | ||
{ | { | ||
# This should never happen with Session.SynchronizeDirectories | # This should never happen with Session.SynchronizeDirectories | ||
- | Write-Host ("Timestamp of {0} kept with its default (current time)" -f $_.Destination) | + | Write-Host ("Timestamp of {0} kept with its default (current time)" -f $e.Destination) |
} | } | ||
} | } | ||
Line 293: | Line 297: | ||
{ | { | ||
# Will continuously report progress of synchronization | # Will continuously report progress of synchronization | ||
- | $session.add_FileTransferred( { FileTransferred } ) | + | $session.add_FileTransferred( { FileTransferred($_) } ) |
# Connect | # Connect |