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

shcsbaker

Awesome- thanks for the point in the right direction
martin

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
shcsbaker

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