Convert to Powershell - SynchronizeDirectories Almost there.

Advertisement

shcsbaker
Joined:
Posts:
10

Convert to Powershell - SynchronizeDirectories Almost there.

trying to convert a batch synchronize file to PowerShell and not sure how to convert the resumesupport switch.

I use a script file and it looks like this:

open sftp://username:password@myftp.com / -hostkey="host key"
synchronize remote -criteria=size -resumesupport=on -delete U:\ /folderA
synchronize remote -criteria=size -resumesupport=on -delete T:\ /folderB
close
exit

Here's what I have so far in my Powershell:

# Load WinSCP .NET assembly
    Add-Type -Path "WinSCPnet.dll"

 # Setup session options
    $sessionOptions = New-Object WinSCP.SessionOptions
    $sessionOptions.Protocol = [WinSCP.Protocol]::sftp
    $sessionOptions.HostName = "myftp.com"
    $sessionOptions.UserName = "username"
    $sessionOptions.Password = "password"
    $sessionOptions.SshHostKeyFingerprint = "ssh info"

    $session = New-Object WinSCP.Session

# Connect
    $session.Open($sessionOptions)

# Synchronize Files
    $session.[WinSCP.TransferResumeSupportState]::On
    $synchronizationResult = $session.SynchronizeDirectories([WinSCP.SynchronizationMode]::Remote,"U:\", "/folderA/", $True)
    $synchronizationResult = $session.SynchronizeDirectories([WinSCP.SynchronizationMode]::Remote,"T:\", "/folderB/", $True)

# Disconnect, clean up
    $session.Dispose()
Again looking for help converting the resumesupport switch and to ensure I've got the rest of the PowerShell script correct.

Thanks,
Kevin

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
28,094
Location:
Prague, Czechia

Re: Convert to Powershell - SynchronizeDirectories Almost there.

$transferOptions = New-Object WinSCP.TransferOptions
$transferOptions.ResumeSupport.State = [WinSCP.TransferResumeSupportState]::On
$synchronizationResult = $session.SynchronizeDirectories([WinSCP.SynchronizationMode]::Remote,"U:\", "/folderA/", $True, $False, [WinSCP.SynchronizationCriteria]::Time, $transferOptions)
$synchronizationResult.Check()
$synchronizationResult = $session.SynchronizeDirectories([WinSCP.SynchronizationMode]::Remote,"T:\", "/folderB/", $True, $False, [WinSCP.SynchronizationCriteria]::Time, $transferOptions)
$synchronizationResult.Check()

See https://winscp.net/eng/docs/library_from_script_transfer_settings

Reply with quote

Advertisement

You can post new topics in this forum