PowerShell synchronise automation
Hi all
Sorry for my English, I'm French.
I tried to use one of your scripts for get some directories and files from a FTP server.
I adapt it for my personal use.
I have an issue at launching of the script:
I want to synchronize local files from FTP!
Thx a lot
cordialy
goro
Sorry for my English, I'm French.
I tried to use one of your scripts for get some directories and files from a FTP server.
I adapt it for my personal use.
I have an issue at launching of the script:
Can you help me please?Overload not found for "SynchronizeDirectories" and the number of arguments "40".
I want to synchronize local files from FTP!
# Load WinSCP .NET assembly Add-Type -Path "C:\Program Files (x86)\WinSCP\WinSCPnet.dll" # Session.FileTransferred event handler function FileTransferred { param($e) if ($e.Error -eq $Null) { Write-Host "Upload of $($e.FileName) succeeded" } else { Write-Host "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 { $sessionOptions = New-Object WinSCP.SessionOptions -Property @{ Protocol = [WinSCP.Protocol]::ftp HostName = "pub-ftp.accor.com" UserName = "ITMaintUSR" Password = "dyhax45y`$" #SshHostKeyFingerprint = "ssh-rsa 2048 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx" } $session = New-Object WinSCP.Session try { # Will continuously report progress of synchronization $session.add_FileTransferred( { FileTransferred($_) } ) # Connect $session.Open($sessionOptions) # Synchronize files $synchronizationResult = $session.SynchronizeDirectories( [WinSCP.SynchronizationMode]::Local, "/MaintenanceIT/OUTILS", "E:\OUTILS", [WinSCP.SynchronizationMode]::Local, "/MaintenanceIT/PRELOAD/POSTE_FIXE/LENOVO TINY M73", "E:\PRELOAD\LENOVO TINY M73", [WinSCP.SynchronizationMode]::Local, "/MaintenanceIT/PRELOAD/POSTE_FIXE/LENOVO M72e", "E:\PRELOAD\LENOVO M72e", [WinSCP.SynchronizationMode]::Local, "/MaintenanceIT/PRELOAD/POSTE_FIXE/HP6305", "E:\PRELOAD\HP6305", [WinSCP.SynchronizationMode]::Local, "/MaintenanceIT/PRELOAD/POSTE_FIXE/HP6005", "E:\PRELOAD\HP6005", [WinSCP.SynchronizationMode]::Local, "/MaintenanceIT/PRELOAD/POSTE_FIXE/HP705G2", "E:\PRELOAD\HP705G2", [WinSCP.SynchronizationMode]::Local, "/MaintenanceIT/PRELOAD/POSTE_FIXE/HP705G1", "E:\PRELOAD\HP705G1", [WinSCP.SynchronizationMode]::Local, "/MaintenanceIT/PRELOAD/POSTE_FIXE/HP_Z240", "E:\PRELOAD\HP_Z240", [WinSCP.SynchronizationMode]::Local, "/MaintenanceIT/MASTER/Tools_Master_SCCM", "E:\Master\Tools_Master_SCCM", [WinSCP.SynchronizationMode]::Local, "/MaintenanceIT/MASTER/Procédure_Master_SCCM", "E:\MASTER\Procédure_Master_SCCM", [WinSCP.SynchronizationMode]::Local, "/MaintenanceIT/MASTER/FOLS/F10", "E:\MASTER\F10", [WinSCP.SynchronizationMode]::Local, "/MaintenanceIT/MASTER/F7.4.X", "E:\MASTER\F7.4.X", [WinSCP.SynchronizationMode]::Local, "/MaintenanceIT/MASTER/Application_Master_V1.4.docx", "E:\MASTER\Application_Master_V1.4.docx", $False) # Throw on any error $synchronizationResult.Check() } finally { # Disconnect, clean up $session.Dispose() } exit 0 } catch { Write-Host "Error: $($_.Exception.Message)" exit 1 }
Thx a lot
cordialy
goro