Advertisement
Guest User

Untitled

a guest
Dec 1st, 2019
544
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.48 KB | None | 0 0
  1. # Load WinSCP .NET assembly
  2. Add-Type -Path "C:\Program Files (x86)\WinSCP\WinSCPnet.dll"
  3.  
  4. function FileTransferred
  5. {
  6. param($e)
  7.  
  8. if ($e.Error -eq $Null)
  9. {
  10. Write-Host "FailOverSyncTool: Upload of $($e.FileName) succeeded"
  11. }
  12. else
  13. {
  14. Write-Host "FailOverSyncTool: Upload of $($e.FileName) failed: $($e.Error)"
  15. }
  16.  
  17. if ($e.Chmod -ne $Null)
  18. {
  19. if ($e.Chmod.Error -eq $Null)
  20. {
  21. Write-Host "Permissions of $($e.Chmod.FileName) set to $($e.Chmod.FilePermissions)"
  22. }
  23. else
  24. {
  25. Write-Host "Setting permissions of $($e.Chmod.FileName) failed: $($e.Chmod.Error)"
  26. }
  27.  
  28. }
  29. else
  30. {
  31. Write-Host "Permissions of $($e.Destination) kept with their defaults"
  32. }
  33.  
  34. if ($e.Touch -ne $Null)
  35. {
  36. if ($e.Touch.Error -eq $Null)
  37. {
  38. Write-Host "Timestamp of $($e.Touch.FileName) set to $($e.Touch.LastWriteTime)"
  39. }
  40. else
  41. {
  42. Write-Host "Setting timestamp of $($e.Touch.FileName) failed: $($e.Touch.Error)"
  43. }
  44. }
  45. else
  46. {
  47. # This should never happen during "local to remote" synchronization
  48. Write-Host "Timestamp of $($e.Destination) kept with its default (current time)"
  49. }
  50. }
  51.  
  52. # Main script
  53.  
  54. try
  55. {
  56. # Sitzungsoptionen TESTSERVER ROOTI
  57. $sessionOptions = New-Object WinSCP.SessionOptions -Property @{
  58. Protocol = [WinSCP.Protocol]::Ftp
  59. HostName = "XXX.XXX.XXX.XX"
  60. UserName = "XXX"
  61. Password = "XXX"
  62. }
  63.  
  64. $session = New-Object WinSCP.Session
  65. try
  66. {
  67. # Will continuously report progress of synchronization
  68. $session.add_FileTransferred( { FileTransferred($_) } )
  69.  
  70. # Connect
  71. $session.Open($sessionOptions)
  72.  
  73. #Compare Files
  74. $comparisonDifferenceCollection = $session.CompareDirectories(
  75. [WinSCP.SynchronizationMode]::Remote, "C:\Users\XXXX\Desktop\WATCHFOLDER", "/DESTINATION", $True ,$False)
  76.  
  77. # Synchronize files
  78. #$synchronizationResult = $session.SynchronizeDirectories(
  79. # [WinSCP.SynchronizationMode]::Remote, "C:\Users\XXXX\Desktop\WATCHFOLDER", "/DESTINATION", $True ,$True)
  80.  
  81. # Throw on any error
  82. #$synchronizationResult.Check()
  83. }
  84. finally
  85. {
  86. # Disconnect, clean up
  87. $session.Dispose()
  88. }
  89.  
  90. exit 0
  91. }
  92. catch
  93. {
  94. Write-Host "Error: $($_.Exception.Message)"
  95. exit 1
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement