Thursday, 17 May 2018

WinScp - Directory Syncing between linux and windows

Import-Module WinScp
$sessionOptions = New-Object WinSCP.SessionOptions
$sessionOptions.Protocol = [WinSCP.Protocol]::Scp
$sessionOptions.HostName = "nash.duckdns.org"
$sessionOptions.UserName = "xyz"
$sessionOptions.Password = "abc"

$sessionOptions.GiveUpSecurityAndAcceptAnySshHostKey = $true
$sessionOptions.SshPrivateKeyPath = "C:\Users\NashAIO\Downloads\Nisa.ppk"

$session = New-Object WinSCP.Session

$session.Open($sessionOptions)

$SourcePath = "C:\Source\"
$DestinationPath = "/home/ubuntu/html/"

$session.SynchronizeDirectories( [WinSCP.SynchronizationMode]::Remote, "$SourcePath", "$DestinationPath", $False)

$session.Dispose()

No comments:

Post a Comment