Post a reply

Options
Add an Attachment

If you do not want to add an Attachment to your Post, please leave the Fields blank.

(maximum 10 MB; please compress large files; only common media, archive, text and programming file formats are allowed)

Options

Topic review

goro

Hi thx for your help
This script works only to FTP from Local:
$session.SynchronizeDirectories(
    [WinSCP.SynchronizationMode]::Remote, "/MaintenanceIT/OUTILS", "E:\OUTILS", $False).Check()

I tried with that but it doesn't work:
$session.SynchronizeDirectories(
    [WinSCP.SynchronizationMode]::Local, "/MaintenanceIT/OUTILS", "E:\OUTILS", $False).Check()

Do you know how can I use this script for synchronize LOCAL FROM FTP?
martin

Re: Powershell synchronise automation

It should be:
$session.SynchronizeDirectories(
    [WinSCP.SynchronizationMode]::Local, "/MaintenanceIT/OUTILS", "E:\OUTILS", $False).Check()
 
$session.SynchronizeDirectories(
    [WinSCP.SynchronizationMode]::Local, "/MaintenanceIT/PRELOAD/POSTE_FIXE/LENOVO TINY M73", "E:\PRELOAD\LENOVO TINY M73", $False).Check()

Etc...
goro

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:
Overload not found for "SynchronizeDirectories" and the number of arguments "40".

Can you help me please?

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