Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Load WinSCP .NET assembly
- Add-Type -Path "C:\Program Files (x86)\WinSCP\WinSCPnet.dll"
- function FileTransferred
- {
- param($e)
- if ($e.Error -eq $Null)
- {
- Write-Host "FailOverSyncTool: Upload of $($e.FileName) succeeded"
- }
- else
- {
- Write-Host "FailOverSyncTool: Upload of $($e.FileName) failed: $($e.Error)"
- }
- if ($e.Chmod -ne $Null)
- {
- if ($e.Chmod.Error -eq $Null)
- {
- Write-Host "Permissions of $($e.Chmod.FileName) set to $($e.Chmod.FilePermissions)"
- }
- else
- {
- Write-Host "Setting permissions of $($e.Chmod.FileName) failed: $($e.Chmod.Error)"
- }
- }
- else
- {
- Write-Host "Permissions of $($e.Destination) kept with their defaults"
- }
- if ($e.Touch -ne $Null)
- {
- if ($e.Touch.Error -eq $Null)
- {
- Write-Host "Timestamp of $($e.Touch.FileName) set to $($e.Touch.LastWriteTime)"
- }
- else
- {
- Write-Host "Setting timestamp of $($e.Touch.FileName) failed: $($e.Touch.Error)"
- }
- }
- else
- {
- # This should never happen during "local to remote" synchronization
- Write-Host "Timestamp of $($e.Destination) kept with its default (current time)"
- }
- }
- # Main script
- try
- {
- # Sitzungsoptionen TESTSERVER ROOTI
- $sessionOptions = New-Object WinSCP.SessionOptions -Property @{
- Protocol = [WinSCP.Protocol]::Ftp
- HostName = "XXX.XXX.XXX.XX"
- UserName = "XXX"
- Password = "XXX"
- }
- $session = New-Object WinSCP.Session
- try
- {
- # Will continuously report progress of synchronization
- $session.add_FileTransferred( { FileTransferred($_) } )
- # Connect
- $session.Open($sessionOptions)
- #Compare Files
- $comparisonDifferenceCollection = $session.CompareDirectories(
- [WinSCP.SynchronizationMode]::Remote, "C:\Users\XXXX\Desktop\WATCHFOLDER", "/DESTINATION", $True ,$False)
- # Synchronize files
- #$synchronizationResult = $session.SynchronizeDirectories(
- # [WinSCP.SynchronizationMode]::Remote, "C:\Users\XXXX\Desktop\WATCHFOLDER", "/DESTINATION", $True ,$True)
- # Throw on any error
- #$synchronizationResult.Check()
- }
- finally
- {
- # Disconnect, clean up
- $session.Dispose()
- }
- exit 0
- }
- catch
- {
- Write-Host "Error: $($_.Exception.Message)"
- exit 1
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement