Topic "Convert to Powershell - SynchronizeDirectories Almost there."

Author Message
shcsbaker
[View user's profile]

Joined: 2014-12-11
Posts: 8
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:

Code:
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:

Code:
# 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
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24995
Location: Prague, Czechia
Code:
$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
shcsbaker
[View user's profile]

Joined: 2014-12-11
Posts: 8
Awesome- thanks for the point in the right direction
Advertisements

You can post new topics in this forum






Search Site

What is WinSCP?

It is award-winning SFTP client, SCP client, FTPS client and FTP client integrated into one software program for file transfer to FTP server or secure SFTP server. [More]

And it's free!

Donate

About donations

$9   $19   $49   $99

About donations

Recommend

WinSCP Privacy Policy

WinSCP License